Skip to content

Exception thrown when using the EncryptToHexStringAsync #46

Description

@selfmadecode

the code below will generate an exception

var iv = KeyGenerators.GenerateRandomIVKeyAsString();
var secretKey = KeyGenerators.GenerateAesSecretKey(128);

//assigning values to the params
var encryptionParameters = new EncryptionParameters
{
DataToEncrypt = "YourDataToEncrypt",
IV = iv,
SecretKey = secretKey
};

var encryptionResult = await encryptor.EncryptToHexStringAsync(encryptionParameters);

The EncryptToHexStringAsync method needs to convert the IV key from Hex string to byte array

THE Cause of the error:
byte[] dataBytes = param.IV.ConvertKeysToBytes();

THE FIX: use the HexadecimalStringToByteArray() e=method to convert the IV to
byte[] dataBytes = param.IV.HexadecimalStringToByteArray();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions