最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use Pkcs5 padding With AES encryption in Cryptojs - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 12

When 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.

发布评论

评论列表(0)

  1. 暂无评论