Out of Memory exception when playing video. RRS feed

  • Question

  • HI

    I am playing a encrypted video file into our UWP app using SymmetricAlgorithmNames.AesCbcPkcs7 algo for decryption. Now a day I am getting "out of memory exception". I am using below code - 

     var contentfolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(PDSConstants.CONTENT_FOLDER_NAME, CreationCollisionOption.OpenIfExists);
                        if (await contentfolder.TryGetItemAsync(fileName) != null)
                            StorageFile sfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(PDSConstants.CONTENT_PATH + fileName, UriKind.Absolute));
                            var fileBasicProperty = await sfile.GetBasicPropertiesAsync();
                            if (fileBasicProperty.Size > 0)
                                IBuffer data = await FileIO.ReadBufferAsync(sfile);
                                IBuffer decrypted = EncryptionDecryptionHelper.Decrypt(PDSConstants.ENCRYPTION_PWD, PDSConstants.ENCRYPTION_SALT, data);
                                if (decrypted != null)
                                    return decrypted.AsStream().AsRandomAccessStream();

    Method for decrypting -

    public static IBuffer Decrypt(string pass, string salt, IBuffer buffMsg)
                    byte[] saltBytes = Encoding.ASCII.GetBytes(salt);
                    KeyDerivationAlgorithmProvider keyDerivationProvider = KeyDerivationAlgorithmProvider.OpenAlgorithm(KeyDerivationAlgorithmNames.Pbkdf2Sha1);
                    IBuffer pwBuffer = CryptographicBuffer.ConvertStringToBinary(pass, BinaryStringEncoding.Utf8);
                    IBuffer saltBuffer = saltBytes.AsBuffer();
                    SymmetricKeyAlgorithmProvider symProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);//AES_CBC_PKCS7
                    CryptographicKey symmKey = symProvider.CreateSymmetricKey(pwBuffer);
                    IBuffer resultBuffer = CryptographicEngine.Decrypt(symmKey, buffMsg, saltBuffer);
                    return resultBuffer;
                catch (Exception ex)
                    LogHelper.ExceptionLogging(ex, "EncryptionDecryptionHelper.Decrypt");
                    //    new Windows.UI.Popups.MessageDialog("DecryptAes_CBC").ShowAsync();
                    return null;

    sandeep chauhan

    Thursday, September 27, 2018 7:04 AM

All replies

  • Hi,

    Could you reproduce the problem every time? Or it just happens randomly? It's hard to tell where the problem is if we do not know the real scenarios.

    I suggest that you could take a look at the Diagnostic Tools of the Visual Studio. This tool helps to show a lot of information related to the performance like memory usage. You could get more information about using that tool here: Quickstart: First look at profiling tools and Diagnostic Tools debugger window in Visual Studio

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 28, 2018 2:56 AM