Object.keys(identityData).forEach(function(field){
        var key = new NodeRSA();
        key.generateKeyPair()
        var value = identityData[field]
        var publicKey = key.exportKey('public')


        var encVal = key.encryptPrivate(value, 'hex')

        var encField = CryptoJS.HmacSHA256(field, publicKey)

        referenceObject[field] = publicKey;
        identityObject[encField] = encVal;
    })
Exemple #2
0
module.exports.mkReqConfigEncrypted = function(config, urlPath, encPayload, unencPayload, method) {
    //payload looks like:
    //   {method: 'POST', body: JSON.stringify(postForm) }

    var key = new NodeRSA();
    var headers = {};
    if(!method) { method = 'POST' }
    if(method != "GET") {
        // encrypt the pyload w/ the private key
        // 
        key.importKey(config.privateKeyMaterial, 'private');
        var postForm = unencPayload;
        headers['Content-Type'] = 'application/json';
        postForm.encPayload = key.encryptPrivate(JSON.stringify(encPayload), 'base64');
        postForm.accessKeyId = config.accessKeyId;
    } else {
        var postForm = null;
    }
    var res = _this.mkReq(urlPath, { method: method, body: JSON.stringify(postForm) }, headers);
    return res;
};