Returning wrong decryption text when using invalid key

大憨熊 提交于 2019-12-13 05:24:57

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6758332/returning-wrong-decryption-text-when-using-invalid-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!