AES128位加密字符串不作为.NET相似 [英] AES128 bit encryption string is not similar as on .net

查看:273
本文介绍了AES128位加密字符串不作为.NET相似的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施AES128位加密/ iOS中的应用程序发送/ .NET从服务器接收数据解密,我几乎做了,但单元测试过程中我得到了加密字符串的一些问题,一些加密的字符串不作为.NET相似服务器,可以说98%的字符串是在两侧正确的,但问题进来2%的字符串,当我搭配两侧加密的字符串,然后在年底的iOS发现生成的字符串是有点短和.net到底是长长的一串。还有一件事,我发现了iOS字符串是.NET串子。当我试图解密的iOS生成的加密字符串,它不解密显示为空,但是当我尝试解密生成的加密字符串.NET服务器(它比iOS的大),我能够瑟解密的字符串。

I am Implementing the AES128 bit encryption/Decryption in iOS application for sending/receiving data from .net server, I almost done but during unit testing I got some issue in encryption string, some encrypted string are not similar as on .net server, Can say 98 percent strings are correct at both side but issue comes in 2 percent strings , when I match the both side encrypted string then found at iOS end generated string is little short and .net end it is long string. One more thing i found the iOS string is the substring of .net string. When i tried to decrypt the iOS generated encrypted string, it is not decrypted showing null but when I try to decrypt the .net server generated encrypted string (it was larger than the iOS) I am able to se the decrypted string.

使用相同的密钥(长在服务器和iOS结束16个字符)。

Using the same KEY(16 character long at server and iOS end).

请你提出解决方案或者我错了。

could you please suggest the solution or where I am wrong .

非常感谢所有。

原始字符串:客户ID = 10安培;模式= 1
KEY =PasswordPassword

Original string: "custId=10&mode=1" KEY= "PasswordPassword"

在iOS的加密字符串:
r51TbJpBLYDkcPC + Ei6Rmg ==

at iOS encrypted string: r51TbJpBLYDkcPC+Ei6Rmg==

在.NET encrpted字符串:
r51TbJpBLYDkcPC + Ei6RmtY2fuzv3RsHzsXt / RpFxAs =

at .net encrpted string: r51TbJpBLYDkcPC+Ei6RmtY2fuzv3RsHzsXt/RpFxAs=

填充加密= kCCOptionPKCS7Padding;

padding for encryption = kCCOptionPKCS7Padding;

我跟着这个教程。
http://automagical.rationalmind.net/2009/02/12/aes-interoperability-between-net-and-iphone/

推荐答案

<一个href=\"http://crypto.stackexchange.com/questions/3022/what-is-the-difference-between-these-aes-encryption-methods\">A在CryptoSE发现

我的版本TL; DR

从本质上讲.NET和iOS设备有不同的实现,既然你是以下的指南是从2009年我希望这是相当过时现在给已经出现在每个平台已经至少1重大修订凸点从那以后。

Essentially .net and iOS both have different implementations, and since the guide you are following is from 2009 I would expect that it is rather out of date by now given there have been at least 1 major revision bump in each of the platforms since then.

原来的答复提供了以下的回答:

我可以马上想到的原因有四:

I can immediately think of four reasons:


  1. 他们都没有使用AES256。我的对象 - 文件中看到一个直接表态,他们正在使用AES256(除非你刻意改变它),我没有看到在Visual Basic文档中说,他们所使用的密钥大小(除非这是任何声明他们由块位)的意思。

  1. They're both not using AES256. I see in the Obj-C document a direct statement that they are using AES256 (unless you deliberately change it), I don't see any statement in the Visual Basic document that says what key size they're using (unless that's what they mean by "Block Bits").

不同的密钥。 AES256需要的256位的密钥;有没有采取五个字符的字符串并转换成这256位值标准方法。现在,有很多可能的方法;有没有特殊的保证,他们都使用相同的。

Different keys. AES256 takes a key of 256 bits; there's no standard method to take a five character string and convert that into a 256 bit value. Now, there are a lot of possible methods; there's no particular assurance that they both use the same one.

不同的操作模式。该AES分组密码采用128位的值,并将其转换成即128位值。然而,并非所有的消息我们可以放入128位,此外,有时也有我们想要做的比其他消息加密其他的东西。操作模式是采用一个分组密码,并使用它作为一种工具来执行一些更普遍有用的功能(例如加密更长消息)的方法。有许多操作的标准模式时,对象 - 文件指出,它正在使用CBC模式;在Visual Basic文档有可能是CBC模式的乱码explination可怕的冠冕堂皇的话。

Different modes of operation. The AES block cipher takes 128-bit values, and translates that into 128-bit values. However, not all our messages can fit into 128 bits, and in addition, sometimes there are other things we'd like to do other than message encryption. A Mode of Operation is a method that takes a block cipher, and uses it as a tool to perform some more generally useful function (such as encrypting a much longer message). There are a number of standard modes of operations, the Obj-C document states that it is using CBC mode; the Visual Basic document has scary sounding words which might be a garbled explination of CBC mode.

的IV。某些操作模式(如CBC模式),具备加密选择初始化向量随机;可以沿着与加密的消息被转换(因为解密将需要的值)。之一的,该初始化向量的确如果加密消息的第二时间,所述第二密文不会像在所有的第一密文的事;这样,有人倾听,将无法推断出你刚才反复的消息。的对象 - 文件特别指出,它会随机挑选一个IV(除非告诉自己给它一个)。

IVs. Some modes of operation (such as CBC mode) have the encryptor select an "Initialization Vector" randomly; that can be translated along with the encrypted message (because the decryptor will need that value). One of the things that this Initialization Vector does if you encrypt the message a second time, the second ciphertext will not resemble the first ciphertext at all; that way, someone listening will not be able to deduce that you've just repeated a message. The Obj-C document specifically says that it will pick a random IV (unless to tell give it one yourself).

正如你可以看到,有一堆的理由两个密文可能会有所不同。有一件事你可以尝试:从一到另一方面的密文,并要求他们进行解密;如果他们能做到,你可以pretty确保双方基本上都做同样的事情。

As you can see, there are a bunch of reasons why the two ciphertexts may be different. One thing you can try: hand the ciphertext from one to the other, and ask them to decrypt it; if they can, you can be pretty sure that both sides are doing basically the same thing.

这篇关于AES128位加密字符串不作为.NET相似的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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