AES/CBC/PKCS5Padding in windows store apps

0

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);
c#
windows
cryptography
windows-8.1
asked on Stack Overflow Apr 15, 2015 by sarvesh • edited Apr 15, 2015 by Artjom B.

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0