-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
Hello,
I would like to encrypt a string using the algorithm 'rijndael-128' in 'ecb' mode.
My key is in binary format.
I create my key with the following code.
var sha256Encrypt = function(key) {
var cipher = crypto.createHash('sha256');
return cipher.update(key, 'utf8').digest('binary');
};
Then I would like to encrypt my message with the key using:
var aes256Encrypt2 = function(message, secret) {
var MCrypt = require('mcrypt').MCrypt;
var rijEcb = new MCrypt('rijndael-128', 'ecb');
rijEcb.validateKeySize(false);
rijEcb.open(secret);
return cipherText = rijEcb.encrypt(message).toString('base64');
};
secret.length is 32. But I get the message:
Key length is not legal.
If I leave the key validation size, I get:
Invalid key size. Available key size are [16, 24, 32]
I know the key should be either a string or a buffer. I did convert my key into a buffer:
var buf = new Buffer(32);
buf.write(key);
It works, but the result is not the one expected.
Would you have any suggestion?
Metadata
Metadata
Assignees
Labels
No labels