You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically, mCrypt is an old library for PHP which has legacy support for modes of operation which are no longer recommended, but whose names collide with official algorithms.
I just need to add an FAQ to the README to explain that to interoperate with mCrypt, you must use its NOFB to be equivalent to the official (and the method used in aes-js) OFB algorithm. There is also no equivalent to mCrypt's OFB in aes-js.
The text was updated successfully, but these errors were encountered:
// An example 128-bit key
var key = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ];
// The initialization vector (must be 16 bytes)
var iv = [ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,35, 36 ];
// Convert text to bytes
var text = 'Text may be any length you wish, padded with PKCS#7.';
var textBytes = aesjs.utils.utf8.toBytes(text);
var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
var encryptedBytes = aesCbc.encrypt(aesjs.padding.pkcs7.pad(textBytes));
// ... what would be the decrypt process?
var text = "Text may be any length you wish (will be padded with PKCS#7).";
// An example 128-bit key
var key = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
// The initialization vector (must be 16 bytes)
var iv = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36];
// CBC instance
var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
// encrypt
var textBytes = aesjs.utils.utf8.toBytes(text);
var encryptedBytes = aesCbc.encrypt(aesjs.padding.pkcs7.pad(textBytes));
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
console.log("encrypted string", encryptedHex);
// decrypt
var encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);
var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
var decryptedBytes = aesCbc.decrypt(encryptedBytes);
var decryptedText = aesjs.utils.utf8.fromBytes(aesjs.padding.pkcs7.strip(decryptedBytes));
console.log("decrypted string", decryptedText);
Any recommendations for generating a secure key and iv?
See #16 for more details.
Basically, mCrypt is an old library for PHP which has legacy support for modes of operation which are no longer recommended, but whose names collide with official algorithms.
I just need to add an FAQ to the README to explain that to interoperate with mCrypt, you must use its NOFB to be equivalent to the official (and the method used in aes-js) OFB algorithm. There is also no equivalent to mCrypt's OFB in aes-js.
The text was updated successfully, but these errors were encountered: