javascript - The wordArray that CryptoJS.AES.decrypt() output was padded with 0x8080808 -


i use cryptojs decrypt encryption web server(use php , aes-128-ecb), can't right wordarray , it's length long. here test code:

var pwd = "abcdefghijklmnop"; var words = [0x86c5464, 0x7335231]; var plain_array= cryptojs.lib.wordarray.create(words); var base64_pwd = cryptojs.enc.utf8.parse(pwd).tostring(cryptojs.enc.base64); var pwd_key = cryptojs.enc.base64.parse(base64_pwd); var encryption = aes.encrypt(plain_array,pwd_key, {mode: cryptojs.mode.ecb,padding: cryptojs.pad.pkcs7}).tostring(); var decrypt = aes.decrypt(encryption,pwd_key, {mode: cryptojs.mode.ecb,padding: cryptojs.pad.pkcs7}); 

and decrypt :

decrypt == {     sigbytes : 8,     words : [0x86c5464, 0x7335231, 0x8080808, 0x8080808]     } 

why decrypt.words padded 0x8080808? how can right length wordarray?

thanks in advance.

aes block cipher , requires input in block size chunks, 16-bytes aes. if data encrypted not multiple of block size padding bytes need added. pkcs#7 padding common padding mode. aes libraries support pkcs#7 padding mode add padding on encryption , remove padding on decryption.

in case 8-bytes of paddig added , 8 bytes of value 0x08.

see pkcs#7 padding.

note: not use ecb mode, insecure, see ecb mode, scroll down penguin. instead use cbc mode random iv, prefix encrypted data iv use in decryption.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -