brix / crypto-js

JavaScript library of crypto standards.
Other
15.78k stars 2.38k forks source link

If the length of iv is less than 16, how does 'crypto-js' pad it (make the iv length expanded to the length of 16) #487

Open ZHAO-Clara opened 6 months ago

ZHAO-Clara commented 6 months ago

If the length of iv is less than 16, how does 'crypto-js' pad it (make the iv length expanded to the length of 16)?

for example i use the following code, what is the ’iv‘ actually used during the encryption process? like '432100000000'?

const CryptoJS = require('crypto-js')
const key = CryptoJS.enc.Utf8.parse('12345678ABCD')
const iv = CryptoJS.enc.Utf8.parse('4321')
let srcs = CryptoJS.enc.Utf8.parse(word)
let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })

Thank you so much

ZHAO-Clara commented 6 months ago

I have the answer. Actually it uses the "null" in ascii to pad iv, in other words, 0x00 in Hex.