I am developing an app in windows 8.1 ,which I want to decrypt an image which was encrypt in "AES/CBC/PKCS5Padding" .
I used "SymmetricAlgorithmNames.AesCbcPkcs7" foe decryption but I am getting an error "The supplied user buffer is not valid for the requested operation. (Exception from HRESULT: 0x800706F8)"
please help me how can I get rid of this error.
If I checked with one sample by taking normal image, I encrypted and decrypted with my methods using "SymmetricAlgorithmNames.AesCbcPkcs7" it was working fine, but the image which was encrypted in server using "AES/CBC/PKCS5Padding" was not decrypting properly.
Uri dataUri = new Uri("ms-appx:///Assets/EncryptedImage.jpg");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
string key = "123456";
IBuffer toDecryptBuffer = await FileIO.ReadBufferAsync(file)
SymmetricKeyAlgorithmProvider aesCbcPkcs7 =
SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
var keyHash = GetMD5Hash(key);
var symetricKey = aesCbcPkcs7.CreateSymmetricKey(keyHash);
IBuffer iv = CryptographicBuffer.GenerateRandom(aesCbcPkcs7.BlockLength);
IBuffer buffDecrypted = CryptographicEngine.Decrypt(symetricKey, toDecryptBuffer , iv);
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
var Newfile = await local.CreateFileAsync("Decrypted.jpg", CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteBufferAsync(Newfile, buffDecrypted);
User contributions licensed under CC BY-SA 3.0