3

我在 c# 中使用 AES 算法进行加密和解密。我使用AesCryptoServiceProvider类进行加密和解密。

这是我在代码中的设置

AesCryptoServiceProvider result = new AesCryptoServiceProvider();
result.BlockSize = 128;
result.KeySize = 256;
result.Mode = CipherMode.CBC;
result.Padding = PaddingMode.PKCS7;

我对我在这里使用的代码是 AES 128 还是 AES 256 的实现有点困惑。

简单的问题是如何识别您使用的是 AES 256 / AES 128 ?

我试过这个链接:http ://social.msdn.microsoft.com/Forums/vstudio/en-US/ac5f4d30-343e-484e-b795-b214820a9327/aes-net-encryption-is-it-always-256-bit -aes

但我没有得到我的答案。

4

2 回答 2

7

它是 AES 256。数字是密钥大小。

来自维基百科

严格来说,AES 标准是 Rijndael 的变体,其中块大小限制为 128 位。

所以块大小总是128。


我无法向您指出任何官方文档,因为(据我所知)AES-<Number>一直是非官方的速记。我可以将您指向 Bruce Schneier 的博客文章,该文章引用了一篇研究论文:

AES 是最著名和使用最广泛的分组密码。它的三个版本(AES-128、AES-192 和 AES-256)的密钥大小(128 位、192 位和 256 位)和轮数(分别为 10、12 和 14)不同。如果是 ...

尽管您的客户可能不喜欢该博客文章的其余部分,因为 Schneier 推荐 AES-128 而不是 AES-256。

于 2013-08-21T07:25:21.113 回答
2

AES 的官方规范是 FIPS-197。它包含以下有关密钥大小和块大小的文本。

1. Introduction

This standard specifies the Rijndael algorithm ([3] and [4]), a symmetric block cipher that can
process data blocks of 128 bits, using cipher keys with lengths of 128, 192, and 256 bits.
Rijndael was designed to handle additional block sizes and key lengths, however they are not
adopted in this standard.

Throughout the remainder of this standard, the algorithm specified herein will be referred to as
“the AES algorithm.” The algorithm may be used with the three different key lengths indicated
above, and therefore these different “flavors” may be referred to as “AES-128”, “AES-192”, and
“AES-256”.

由于 NIST 在竞赛后选择 Rijndael 作为 AES,因此您无法获得更权威的参考。

请注意,尽管您的代码还包含 CBC 和 PKCS#7 填充,但它们不是 AES 规范的一部分。不过,CBC 是 NIST 批准的分组密码操作模式(请参阅 NIST SP 800-38A)。该规范还提到 NIST 没有考虑填充方案,可能是因为它们不应该用作提供任何安全性的算法(即对于分组密码模式)。

于 2013-08-31T21:22:26.110 回答