Reputation: 11
I am writing the DES encryption code using NodeJS.
According to the DES algorithm, the result should be like this,
* http://www.unsw.adfa.edu.au/~lpb/src/DEScalc/DEScalc.html
An example DES test value, taken from
"H. Katzan, The Standard Data Encryption Algorithm, pp75-94, Petrocelli Books Inc., New York, 1977" is:
Key: 5B5A57676A56676E (HEX)
Plaintext: 675A69675E5A6B5A (HEX)
Ciphertext: 974AFFBF86022D1F (HEX)
However, my code prints somewhat different values.
var assert = require("assert");
var crypto = require("crypto");
var plaintext = new Buffer( '675A69675E5A6B5A', 'hex' ).toString( 'binary' );
var key = new Buffer( '5B5A57676A56676E', 'hex' ).toString( 'binary' );
var cipher = crypto.createCipher( 'des-ecb', key );
var c = cipher.update( plaintext, 'binary', 'hex' );
c += cipher.final( 'hex' );
console.log( c );
What should I fix in the upper code?
Upvotes: 1
Views: 3548
Reputation: 2306
5B5A57676A56676E is the Key, not password.
var crypto = require("crypto");
var plaintext = new Buffer( '675A69675E5A6B5A', 'hex' ).toString( 'binary' );
console.log("plian:"+plaintext);
var key = new Buffer( '5B5A57676A56676E', 'hex' );
var iv = new Buffer(8);
iv.fill(0);
var cipher = crypto.createCipheriv("des", key, iv);
cipher.setAutoPadding(false);
var c = cipher.update( plaintext, 'binary', 'hex' );
c+=cipher.final('hex' );
console.log(c);
Upvotes: 5