I am trying to implement a simple Encryption of a string.
I am getting "The supplied user buffer is not valid for the requested operation" error. I dont know what is the problem in the implementation.
Below is the code snippet.
var keyHash = GetMD5Hash(key);
var toDecryptBuffer = CryptographicBuffer.ConvertStringToBinary(toEncrypt, BinaryStringEncoding.Utf8);
var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);
var symetricKey = aes.CreateSymmetricKey(keyHash);
var buffEncrypted = CryptographicEngine.Encrypt(symetricKey, toDecryptBuffer, null);
`
The length of the data in toEncrypt
must be a multiple of the block length of the algorithm unless you are using PKCS7 padding, which you currently aren't. You need to manually pad the data or use PKCS7 padding.
var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.aesEcbPkcs7);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With