add crypto to pinService and tests
This commit is contained in:
parent
0c0e11aad3
commit
65512bf1c2
4 changed files with 129 additions and 62 deletions
|
|
@ -59,22 +59,22 @@ module.exports = {
|
|||
/**
|
||||
* Encrypts symmetrically using a passphrase
|
||||
*/
|
||||
encrypt: function(key, message) {
|
||||
encrypt: function(key, message, salt, iter) {
|
||||
if (!_.isString(message)) {
|
||||
message = JSON.stringify(message);
|
||||
}
|
||||
sjcl.json.defaults.salt = defaultSalt;
|
||||
sjcl.json.defaults.iter = defaultIterations;
|
||||
sjcl.json.defaults.salt = salt || defaultSalt;
|
||||
sjcl.json.defaults.iter = iter || defaultIterations;
|
||||
return sjcl.encrypt(key, message);
|
||||
},
|
||||
|
||||
/**
|
||||
* Decrypts symmetrically using a passphrase
|
||||
*/
|
||||
decrypt: function(key, cyphertext) {
|
||||
decrypt: function(key, sjclEncryptedJson) {
|
||||
var output = {};
|
||||
try {
|
||||
return sjcl.decrypt(key, cyphertext);
|
||||
return sjcl.decrypt(key, sjclEncryptedJson);
|
||||
} catch (e) {
|
||||
log.info('Decryption failed due to error: ' + e.message);
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue