Rijndael decryption in WinRT

本文关键字:WinRT in decryption Rijndael | 更新日期: 2023-09-27 18:17:26

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

  • 键是固定的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;

Rijndael decryption in WinRT

CBC需要IV(也是CryptographicEngine.encryptCryptographicEngine.decryptIBuffer),因此您不能提供null。这只是为decrypt函数引用的encrypt函数写的。