I just need to use cryptojs AES encryption but with padding Pkcs5 which i can not find in Cryptjs document, i want to do this because it is desired from the backend. it worked fine with Pkcs7 and cypher mode ECB, how to convert this function to work with Pkcs5
encryptByAES: function (secretPwd) {
var keyHex = CryptoJS.enc.Utf8.parse(this.encryption_key);
var encrypted = CryptoJS.AES.encrypt(secretPwd, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log('encryptByAES key: ',encrypted.toString());
return encrypted.toString();
}
I just need to use cryptojs AES encryption but with padding Pkcs5 which i can not find in Cryptjs document, i want to do this because it is desired from the backend. it worked fine with Pkcs7 and cypher mode ECB, how to convert this function to work with Pkcs5
encryptByAES: function (secretPwd) {
var keyHex = CryptoJS.enc.Utf8.parse(this.encryption_key);
var encrypted = CryptoJS.AES.encrypt(secretPwd, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log('encryptByAES key: ',encrypted.toString());
return encrypted.toString();
}
Share
Improve this question
asked Nov 22, 2016 at 9:50
Mohamed A. SheblMohamed A. Shebl
3843 gold badges5 silver badges17 bronze badges
1 Answer
Reset to default 12When used with AES there is no difference betwheen PKCS#5 & PKCS#7.
The difference between the PKCS#5 and PKCS#7 padding is the block size it supports. PKCS#5 only works with 8-byte blocks whereas PKCS#7 works with block sizes betwheen 1 and 255 bytes. AES uses block size of 8 bytes.