Skip to content

Security problem with the IV AES #9

@ByteDecoder

Description

@ByteDecoder

Since the library is always using the same IV, is potentially fragile in terms of security.

byte[] iv = new byte[16];

Here always the IV vector is initialized to the same value. What it should be, every encrypted value must have a different IV and also add this IV block to the final ciphertext, to have the different values as result.

The IV is not a secret, so is safe to be included in the final ciphertext.

The .Net Aes already has a random IV value when is created:

`
using (Aes myAes = Aes.Create())
{

        // Encrypt the string to an array of bytes.
        byte[] encrypted = EncryptStringToBytes_Aes(original, myAes.Key, myAes.IV);

`

If you see, the AES instance when is used with Aes.Create() already create an IV.

A possible solution is to create a new buffer that combines these two values as:

Buffer.BlockCopy(iv, 0, result, 0, iv.Length); Buffer.BlockCopy(encryptedContent, 0, result, iv.Length, encryptedContent.Length);

An also, since probably is using the library, should probably be needed to create a migration plan to encrypt properly the actual data encrypted by the library by projects that used it.

For the decryption, you need to split the hypertext and the IV from the block, and from there, you can use the key, and the unique IV to decrypt the value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions