问题
I am new in windows phone development. How can I use AES/ECB/PKCS7Padding algorithm in WP7 ?.
While googled I saw many suggested about Bouncy Castle. But I did not clearly understood about this Bouncy Castle. Is this an algorithm ?.
I need to encrypt/decrypt password for sending to server. In all other phone (Android, iPhone, Blackberry), we use AES/ECB/PKCS7Padding algorithm for this. They all give same ecrypted/decrypt result for our input. But in windows phone I used AesManaged Class for the encryption. But it gives different encrypted result. In the msdn documentation (MSDN documentation) about AESManaged class they said "The cipher mode is always CBC, and the padding mode is always PKCS7". I think maybe thats why here I am getting different encrypted result comparing to other phones.
Is that the problem here ?. If its, then how can I use AES/ECB/PKCS7Padding algorithm in WP7 ?
I dont see any property for setting the cipher mode in AesManaged class.
Thanks.
回答1:
If you want to use AES/ECB/PKCS7Padding in Windows Phone, you should use Bouncy Castle library.
This library wasn't made exactly for Windows Phone, and you can't use the dll from Bouncy Castle site. Instead, you should download the WP7-ported library from here. (two links at the bottom of the article)
Now, you can use Org.BouncyCastle.Crypto.IBufferedCipher type.
cipher = CipherUtilities.GetCipher("AES/ECB/PKCS7"); // or PKCS7PADDING, no matter
cipher.Init(false, new KeyParameter(key)); // or something else
Then you should work with this variable.
And yes,
"The cipher mode is always CBC, and the padding mode is always PKCS7"
that's why you are getting wrong result.
来源:https://stackoverflow.com/questions/11733424/how-use-aes-ecb-pkcs7padding-algorithm-in-windows-phone-7