1

我在我的 windows phone 项目中使用 BouncyCastle dll。但是会抛出一个错误:

找不到方法:GetCipher Org.BouncyCastle.Security.CipherUtilities。

有什么问题?以下是我的用法:

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;

和我的代码:

**string result = decrypt("string", "key");//error here!**

public static string decrypt(string encryptedhexstring, string password)
        {
            #region decrypt

            //Covert from hexstring to bytearray
            byte[] encryptedData = Encoding.UTF8.GetBytes(encryptedhexstring);

            var key = Encoding.UTF8.GetBytes(password);
            // AES algorthim with ECB cipher & PKCS5 padding...
            var cipher = CipherUtilities.GetCipher("AES/ECB/PKCS5PADDING");

            // Initialise the cipher...
            cipher.Init(false, new KeyParameter(key));

            // Decrypt the data and write the 'final' byte stream...
            var decryptionbytes = cipher.ProcessBytes(encryptedData);
            var decryptedfinal = cipher.DoFinal();

            // Write the decrypt bytes & final to memory...
            var decryptedstream = new MemoryStream(decryptionbytes.Length);
            decryptedstream.Write(decryptionbytes, 0, decryptionbytes.Length);
            decryptedstream.Write(decryptedfinal, 0, decryptedfinal.Length);
            decryptedstream.Flush();

            var decryptedData = new byte[decryptedstream.Length];
            decryptedstream.Position = 0;
            decryptedstream.Read(decryptedData, 0, (int)decryptedstream.Length);

            // Convert the decrypted data to a string value...
            var resultdecrypted = Encoding.UTF8.GetString(decryptedData, 0, decryptedData.Length);

            return resultdecrypted;

            #endregion
        }
4

0 回答 0