如何在Windows Phone 7中使用AES / ECB / PKCS7Padding算法? [英] How use AES/ECB/PKCS7Padding algorithm in Windows Phone 7?

查看:228
本文介绍了如何在Windows Phone 7中使用AES / ECB / PKCS7Padding算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows Phone开发中是新的。如何在WP7中使用AES / ECB / PKCS7Padding算法?



虽然我们看到许多关于Bouncy Castle的建议。但是我没有清楚地了解这个Bouncy城​​堡。这是算法吗?



我需要加密/解密发送到服务器的密码。在所有其他手机(Android,iPhone,Blackberry)中,我们使用AES / ECB / PKCS7Padding算法。它们都为我们的输入提供相同的加密/解密结果。但是在Windows Phone中,我使用了AesManaged Class进行加密。但它给出不同的加密结果。 msdn文档( MSDN文档)关于AESManaged类,他们说密码模式总是CBC,填充模式总是PKCS7。我想也许这就是为什么在这里我得到不同的加密结果与其他手机相比。



这是问题吗?如果是,那么如何在WP7中使用AES / ECB / PKCS7Padding算法?



我没有看到任何属性用于在AesManaged类中设置密码模式。



谢谢。

解决方案

如果要在Windows中使用AES / ECB / PKCS7Padding电话,你应该使用Bouncy Castle图书馆。



这个库不是用于Windows Phone的,不能使用Bouncy Castle网站的dll。相反,您应该从此处。 (文章底部的两个链接)



现在,您可以使用Org.BouncyCastle.Crypto.IBufferedCipher类型。

  cipher = CipherUtilities.GetCipher(AES / ECB / PKCS7); //或PKCS7PADDING,不管
cipher.Init(false,new KeyParameter(key)); //或其他东西

然后你应该使用这个变量。



是的,


密码模式始终为CBC,填充模式始终为PKCS7 p>

这就是为什么你得到错误的结果。


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.

解决方案

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.

这篇关于如何在Windows Phone 7中使用AES / ECB / PKCS7Padding算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆