Search This Blog

Thursday, April 26, 2018

Nodejs - Decrypt for AES-256-CBC with no padding.

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 );

Post a Comment

Hit Counter


View My Stats