使用无效键时返回错误的解密文本 [英] Returning wrong decryption text when using invalid key

查看:127
本文介绍了使用无效键时返回错误的解密文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



http://code.google.com/p/iphonebits/source/browse/trunk/src/Encryption/NSData- AES.m?r = 2



这样做完美。但是,当我使用无效的密钥(除加密密钥以外的任何一个)解密加密的文本时,这将返回一些文本,而不是解密文本的实际长度。什么原因(这应该返回零)?这是更好的方法吗?图书馆应该为无效解密密钥返回错误吗?这是不是必须的?



谢谢

解决方案

嗯,算法不知道你提供的关键是正确的。要知道密钥是否正确,算法将不得不将其复制,这是不安全的。虽然它可能具有它的哈希的副本,但仍然适用于加密和解密算法只能工作一个键。您当前的解密接受密钥,并将其置于解码算法中。结果应该反映原始文本,但如果键错误,它将给你根据错误的键生成的文本。这一切都正常工作。


I use following class to encrypt/decrypt my texts.

http://code.google.com/p/iphonebits/source/browse/trunk/src/Encryption/NSData-AES.m?r=2

This works perfectly. But when I decrypt the encrypted text with an invalid key (any one other than encryption key) this returns some text and its not in the actual length of the decrypted text. What can be the reason (is this supposed to return nil)? Is this the better way? Does libraries supposed to return errors for invalid decryption keys? Is it a must or not?

Thank you

解决方案

Well, the algorithm will not know if the key that you are providing is the right one. To know if the key is right the algorithm would have to have it's copy, which is unsafe. Although it could have the copy of it's hash, but that would still apply that the encryption and decryption algorithms would work for only one key. Your current decryption accepts the key and put's it to work in the decoding algorithm. The result should reflect the original text but if the key was wrong it will give you the text generated according to the wrong key. It's all working properly.

这篇关于使用无效键时返回错误的解密文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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