How use AES/ECB/PKCS7Padding algorithm in Windows

2020-03-29 13:52发布

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条回答
祖国的老花朵
2楼-- · 2020-03-29 14:56

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.

查看更多
登录 后发表回答