Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
Merge pull request #586 from stormpath/fix/crypto-deprecation
Browse files Browse the repository at this point in the history
Fix/crypto deprecation
  • Loading branch information
robertjd authored Feb 4, 2017
2 parents deb7165 + 9ebf4dd commit b9bbfc3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/resource/ApiKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ ApiKey.prototype._getDecryptedSecret = function _getDecryptedSecret(callback) {
var encryptedSecret = new Buffer(this.secret,'base64');
var iv = encryptedSecret.slice(0,16);
var rawEncryptedValue = encryptedSecret.slice(16);
crypto.pbkdf2(password,new Buffer(salt,'base64'),iterations,(keyLengthBits/8),function(err,key){
var saltBuf = new Buffer(salt,'base64');
var keyLength = keyLengthBits / 8;
var cryptoCallback = function(err, key){
if(err){
return callback(err);
}
Expand All @@ -61,7 +63,14 @@ ApiKey.prototype._getDecryptedSecret = function _getDecryptedSecret(callback) {
return callback(e);
}
callback(null,decrypted);
});
};

try {
crypto.pbkdf2(password,saltBuf,iterations,keyLength,'sha1',cryptoCallback);
} catch (e) {
// Node 0.10.0 support - It does not take the digest parameter, and throws
crypto.pbkdf2(password,saltBuf,iterations,keyLength,cryptoCallback);
}
};

ApiKey.prototype._setApiKeyMetaData = function _setApiKeyMetaData(obj){
Expand Down

0 comments on commit b9bbfc3

Please sign in to comment.