import * as crypto from 'crypto';

function _md5hex(data) {
    let hash = crypto.createHash('md5');
    return hash.update(data).digest('hex');
}

class SignUtils {

    sign(data: object, signKey: string) {
        let array = [];
        Object.keys(data).forEach(key => {
            array.push(key + '=' + data[key])
        })
        let signStr = array.sort().join("&");
        signStr += '&' + signKey
        return _md5hex(signStr)
    }

}

export default new SignUtils()