Node encryption and decryption coding problem

wrote a node encryption and decryption demo, encountered encoding problems. createCipheriv and createDecipheriv methods are used for encryption and decryption respectively

node version

343d083990e4a863597ebc429e69552f
hello world

two questions

1 how to determine the length of key and iv corresponding to encryption algorithms such as CBC, and what role do key and iv play in encryption respectively? When
2, the output code is utf8 , why is the output garbled like 49 "cY~" B "iU/ ?

Apr.10,2021

AES-128-CBC is, as the name implies, a 128bit key AES block cipher, and CBC means that the encryption mode used when encrypting is password block chain mode.

AES encryption process is available on Baidu, don't bother to copy, IV is used by initial Value, to initialize packets before the first encryption, 16 bytes, 128bits.

UTF8 is a character code, and what is encrypted by AES is a string of unpredictable binary codes. If you forcibly encode a character, of course the code is garbled. Base64 is not character coding, but a coding method in which binary bits are converted into printable characters, so you think it is very normal, because it has only 64 characters to print. Hex16 means 16 characters can be printed, and there is no garbled code. So there's nothing wrong with it

Menu