使用加密货币++在 iPhone sdk 上,在应用程序引擎上使用 pycrypto

发布于 2024-09-01 09:48:47 字数 822 浏览 4 评论 0原文

我正在尝试使用 crypto++ 加密 http 请求,并在应用程序引擎服务器端使用 pycrypto 解密它们。使用Arc4加密,我可以在iPhone端成功加密和解密,但是当我尝试在App Engine上解密时,结果是乱码。在客户端加密后的密文与我检查日志记录时在服务器上收到的文本相同,所以如果它们看起来相同,为什么解密会失败?

我想这可能与 NSString 的编码有关,因为我发现我需要在解密之前在服务器端的密码上调用encode(),以避免在尝试将密码编码为ascii时decrypt()失败。我有一篇单独的文章对此进行了深入研究。有人可以提供一些建议吗?

crypto++ / pycrypto with Google App Engine

更新: 我发现用 Crypto++ 在 C 中加密得到的密文与用 PyCrypto 在 python 中加密得到的密文不同。我在初始化密钥时可能做错了什么吗?我做了类似的事情:

    ARC4::Encryption enc("a");

在C中。在Python中我做:

testobj=ARC4.new('a')

%编码的结果密码在C中与在Python中不同。我注意到在 C 中,我可以传递密钥长度的第二个参数,我猜测“a”应该为 1,从而产生与不输入参数时不同的密码。不过,% 编码的结果仍然与 python 编码不同。

也许我的 init 看起来有什么特别不对劲的地方吗?

I'm trying to encrypt http requests using crypto++ and decrypt them with pycrypto on the app engine server end. Using Arc4 encryption, I can successfully encrypt and decrypt on the iphone end but when I try decrypting on app engine, the result is garbled. The ciphertext after encrypting on the client is the same as the text received on the server when I check logging, so if they are visually the same, why would decrypting fail?

I thought maybe it has something to do with the encoding of the NSString, as I find I need to call encode() on the cipher on the server end before decrypting just to avoid decrypt() failing on it attempting to encode the cipher in ascii. I have a separate post that delves a bit into this. Can anyone offer some advice?

crypto++ / pycrypto with google app engine

Update:
I have discovered that the ciphertext resulting from encrypting in C with Crypto++ is not the same as the ciphertext from encrypting in python with PyCrypto. Could there be something I'm doing wrong with initializing the keys? I do something like:

    ARC4::Encryption enc("a");

in C. And in python I do:

testobj=ARC4.new('a')

The %-encoded resulting cipher is different in C than in python. I noticed that in C, I can pass a 2nd parameter for keylength, which I guessed should be 1 for "a", resulting in a different cipher than when putting no parameter. The %-encoded result was still different from the python encoding, though.

Does anything look particularly amiss with my init perhaps?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木格 2024-09-08 09:48:47

我发现问题不在于任何一个 crypto impl 的 init ,而是错误地尝试将加密的密文填充到 NSString 中,而 NSString 不能简单地获取没有特定编码的原始二进制数据。诀窍是将数据编码为 Base64 或 Base16,使其可读,然后在解密之前在服务器端使用 unhexlify。

I've discovered that the problem was not with the init of either crypto impl but rather mistakenly trying to stuff the encrypted cipher text into an NSString which cant simply take raw binary data with no particular encoding. The trick was to encode the data in base64 or base16 so that it is is readable, then use unhexlify on the server end before decrypting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文