Some AES encryption modes (e.g. CBC) need a random generated initialization vector (iv). The codes will generate an iv with size of 16 byte = 128 bit.
The iv output format is a byte array but when sending this iv to another system or persons you often need another (string based) format - so I'm providing the iv also as a Base64 encoded string.
This is a serious warning regarding the security of the programs shown in these article series. Always keep in mind my disclaimer regarding my programs: All programs are for educational purposes and are not intended to use in production or any other programs where a secure solution is needed. The programs do not have proper exceptional/error handling and in some cases they use insecure key lengths or other methods that are insecure. Never ever use the programs in real life unless checked by a qualified professional cryptographer.
The following links provide the solution in code and within an online compile that runs the code.
*1) you need the external library pointycastle version 3.1.1
*2) the Go version is a combined one: generate AES key, IV and nonce in one program
This is an output (as there is a random element your output will differ):
Generate a 16 byte long Initialization vector (IV)
generated iv length: 16 base64: PnujuygIgaMxwdQRWz9wvA==
Last update: Oct. 18th 2021
Back to the main page: readme.md