none
Windows8 AES加密解密问题?为什么加密后 解密跟原文件不一样呢? RRS feed

  • 问题

  • SymmetricKeyAlgorithmProvider aesProvider;
            CryptographicKey aesKey;
            IBuffer iv;
            IBuffer bufferout;
            string str = "ksldfjlskdfjldskfsldjfghhhhhhhhhhhhhhhhhhhh";
            private async void Button_Click_1(object sender, RoutedEventArgs e)
            {
                aesProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
                IBuffer key = CryptographicBuffer.DecodeFromHexString("12345678901234561234567890123456");
                IBuffer key1 = CryptographicBuffer.ConvertStringToBinary("1234567890123456", BinaryStringEncoding.Utf8);
                aesKey = aesProvider.CreateSymmetricKey(key);
                    
                IBuffer buffer = CryptographicBuffer.DecodeFromBase64String(str);
                iv = CryptographicBuffer.GenerateRandom(aesProvider.BlockLength);

                bufferout= CryptographicEngine.Encrypt(aesKey, buffer, iv);
     
                MessageDialog dialog = new MessageDialog(CryptographicBuffer.EncodeToBase64String(bufferout));
               await dialog.ShowAsync();
            }

            private async void Button_Click_2(object sender, RoutedEventArgs e)
            {
               // aesProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
                //aesKey = aesProvider.CreateSymmetricKey(CryptographicBuffer.ConvertStringToBinary("1234567890123456", BinaryStringEncoding.Utf8));

     

                bufferout = CryptographicEngine.Decrypt(aesKey, bufferout, iv);

                MessageDialog dialog = new MessageDialog(CryptographicBuffer.EncodeToBase64String(bufferout));
                await dialog.ShowAsync();
             }

    以上代码代码--------------------------------------------------------------------------------------------------

    为什么解密加密后的字符串 跟原始字符串不一致呢?

    2013年3月5日 10:13

答案