2

Background: I've written a pair of .NET functions for AES encryption/decryption.

I want to store the IV with the ciphertext in a single base64 encoded string, similar to as described here.

I've seen hashing this example where he appends the salt bytes to the end of the hash bytes, and then base64 encodes the new array. Then, when verifying the hash, he decodes the base64 string, and splits out the salt and hash bytes.

My question is: are there defined standards that describe how I should be performing the concatenation, so that my base64 encoded data could be parsed & decrypted by other programs? Or is it just up to me as the programmer to write my encrypt/decrypt functions to parse the data as I see fit?

The standards would answer questions like: Do I prepend or append the IV bytes to the ciphertext bytes?

My ideal function signature would look like:

// returns base64encodedCiphertextAndIV
string encrypt(string plaintext, string base64encodedKey)  

// returns plaintext
string decrypt(string base64encodedCiphertextAndIV, string base64encodedKey)
4

1 回答 1

2

将 IV 添加到密文的前面是非常好的,并且非常标准。IV不必保密,只有密钥必须保密。如果您使用的是 CTR 模式,那么 IV 在给定键中的唯一性非常重要。如果您使用 CBC 模式,则拥有唯一的 IV 很有用,但不是那么重要。

于 2012-04-08T20:52:33.757 回答