var crypto = require ( 'crypto' );
algorithm = 'aes-256-cbc';
function decrypt ( key, data )
{
var sha256 = crypto.createHash ( 'sha256' );
sha256.update ( key );
var input = new Buffer ( data, 'base64' ),
iv = Buffer.alloc(16);
ciphertext = input,
decipher = crypto.createDecipheriv( algorithm, sha256.digest (), iv ),
plaintext = decipher.update ( ciphertext );
plaintext += decipher.final ();
return plaintext
};
var deCodeValue = new Buffer ( "encrypted-content-place-here", 'base64' ).toString ( 'utf-8' );
console.log(deCodeValue);
var p = decrypt ( 'password', deCodeValue );
console.log ( p );
algorithm = 'aes-256-cbc';
function decrypt ( key, data )
{
var sha256 = crypto.createHash ( 'sha256' );
sha256.update ( key );
var input = new Buffer ( data, 'base64' ),
iv = Buffer.alloc(16);
ciphertext = input,
decipher = crypto.createDecipheriv( algorithm, sha256.digest (), iv ),
plaintext = decipher.update ( ciphertext );
plaintext += decipher.final ();
return plaintext
};
var deCodeValue = new Buffer ( "encrypted-content-place-here", 'base64' ).toString ( 'utf-8' );
console.log(deCodeValue);
var p = decrypt ( 'password', deCodeValue );
console.log ( p );
No comments:
Post a Comment