开发者

Generate Initialization Vector (IV) and Salt values in .NET

I am using the .NET Cryptography libraries to encrypt/decrypt some text. I would like to generate the Initialization Vector (IV) and Salt for the user during encryption so that all they need to provide is a Pass-Phrase. Once the text has been encrypted I will present the Salt value and Initialization Vector to the user so that they can pass them along to the receiver of the message.

How do I use .NET to generate the salt and Initialization Vector (IV) outside of the actual encryption steps? Currently the encryption/decryption methods I have created accept the salt and initialization vector as parameters, as Strings.

I tried using the following code the generate an initialization vector but the size of the retu开发者_如何学Pythonrn value always coming back larger than the 16 bytes required for the initialization vector in AES.

Dim rng As New RNGCryptoServiceProvider()
Dim buff As Byte() = New Byte(15) {}
rng.GetBytes(buff)
Return Convert.ToBase64String(buff)


The size of the IV is determined by the algorithm you use (for example, 16 bytes). It means the byte array size is fixed, not the string you build from it. You can't pass a string as an IV unless you can convert it to the proper byte array with the required size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜