调试和发布模式下的AES加密问题 [英] AES encryption problem in Debug and Release mode

查看:371
本文介绍了调试和发布模式下的AES加密问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AES加密算法(Rijndael实现)。我正在使用MS Visual Studio 2008 IDE进行开发工作。在调试和发布模式下,我可能会看到一个奇怪的问题。当我在调试模式下加密字符串时,它与释放模式下生成的字节不同。但是幸运的是解密将得到相同的字符串。我在Mac中尝试过,它可以再生成一个字节序列,但能够正确解密所有字节序列。

I am using AES encryption algorithm (Rijndael implementation). I am using MS Visual Studio 2008 IDE for my development work. I could see a strange problem in my Debug and Release mode. When I encrypt a string in Debug mode it generates different bytes than Release mode. But fortunately decrypting will result same string. I have tried in Mac, it generates one more byte sequence but able to decrypt all byte sequences correctly.

此问题与加密算法或调试/发布设置有关吗?
是否有解决方案可以避免这种情况?

Is this problem related to encryption algorithm or Debug/Release settings? Is there any solution to avoid this?

关于
Devara Gudda

Regards Devara Gudda

推荐答案

AES是一个 block 密码。您可以使用它加密和解密128位固定大小的块。为了加密和解密更长的序列,您通常使用某种操作模式和某种填充方案,它们都可能通过IV(初始化向量)和填充而涉及一些随机数。在那些情况下,由于涉及的随机性,密文每次都会更长一些并且有所不同。实际上,同一封邮件会加密为不同的密文,这并不是一个坏特性。您甚至需要它来保护自己免受某些攻击。

AES is a block cipher. You can encrypt and decrypt blocks of a fixed size of 128 bits with it. To encrypt and decrypt longer sequences you typically use a certain "mode of operation" and a certain "padding scheme" which both might involve some randonmess via the IV (initialization vector) and padding. In those cases the cipher text will be a bit longer and different each time due to the "randomness" that is involved. Actually, it's not a bad property that the same message encrypts to different cipher texts. You even need this to protect yourself from certain attacks.

这篇关于调试和发布模式下的AES加密问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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