【问题标题】:Rijndael decryption in WinRTWinRT 中的 Rijndael 解密
【发布时间】:2014-08-11 20:33:14
【问题描述】:

我正在尝试编写一个解密字节数组的方法。

  • 密钥固定24字节

我在实际解密数据时遇到异常The supplied user buffer is not valid for the requested operation,希望有人能帮助我!

        // Get the key and put into IBuffers

        IBuffer keyBuffer = CryptographicBuffer.CreateFromByteArray(cKey);
        IBuffer plainText = CryptographicBuffer.CreateFromByteArray(cData);
        byte[] decryptedData;

        // Setup an AES key, using AES in CBC mode and applying PKCS#7 padding on the input
        SymmetricKeyAlgorithmProvider aesProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcbPkcs7);
        CryptographicKey aesKeySymm = aesProvider.CreateSymmetricKey(keyBuffer);


        // Decrypt the data and convert it to byte array

        // EXCEPTION ON THIS LINE: "The supplied user buffer is not valid for the requested operation."
        IBuffer decrypted = CryptographicEngine.Decrypt(aesKeySymm, plainText, null);
        CryptographicBuffer.CopyToByteArray(decrypted, out decryptedData);
        return decryptedData;

【问题讨论】:

  • 我已经编辑了您的问题,以使您收到的实际异常更加明显,请注意 :)

标签: c# encryption windows-runtime aes


【解决方案1】:

CBC 需要一个 IV(对于 CryptographicEngine.encryptCryptographicEngine.decrypt,也需要一个 IBuffer,因此您不能提供 null。这仅针对 decrypt 函数引用的 encrypt function 编写。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2012-05-06
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多