1

我需要在 a) Unicode 字符中为 AES-256 制作强密钥,b) 以字节为单位的密钥。

a) 我必须生成 50 个随机 Unicode 字符,然后将它们转换为字节。这可以使用 Unicode 字符作为 AES256 密钥吗?例如,我想使用此页面创建密码。有什么方法可以将 Windows 字符表中的所有字符导入 Windows Form App 中的程序?

b)我正在使用此代码:

System.Security.Cryptography.AesCryptoServiceProvider key = new System.Security.Cryptography.AesCryptoServiceProvider();
key.KeySize = 256;
key.GenerateKey();
byte[] AESkey = key.Key;

够了还是我应该改变一些东西?

我还有一个问题。使 AES 密钥长于 43 个 ASCII 字符会更安全,还是会被散列到 256 位?43个字符和100个字符的ASCII键有区别吗?

4

1 回答 1

2

a) 我必须生成 50 个随机 Unicode 字符,然后将它们转换为字节。这可以使用 Unicode 字符作为 AES256 密钥吗?

是的,这是可能的。由于您有足够的字符空间,您可以对其进行编码。ceil(32 / 3) * 4 = 44,所以你有足够的字符来做这个。不过,您不会使用 Unicode 编码提供的额外空间。显然,您需要在使用它之前将其转换回二进制文件。

b)aes.GenerateKey“足够”了吗?

是的,aes.GenerateKey足以生成二进制 AES 密钥。

c) 使 AES 密钥长于 43 个 ASCII 字符会更安全,还是会被散列到 256 位?43个字符和100个字符的ASCII键有区别吗?

AES 密钥根本没有经过哈希处理。它只是 128、192 或 256 位(即 16、24 或 32 字节)的数据,应该与随机(当然,对于不知道该值的人)无法区分。如果你想散列一些东西,你必须自己做——但请继续阅读。

要理解的重要一点是密码不是密钥,现代密码的密钥几乎总是被编码为二进制。对于 AES,没有 ASCII 密钥这样的东西。如果您需要对密钥进行编码,请使用 base 64。

If you want to use a password then you need to use a key derivation function or KDF. Furthermore, if you want to protect against dictionary and rainbow table attacks you will want to use a password based key derivation function or PBKDF. Such a KDF is also called a "password hash". In case of .NET your best bet is Rfc2898DeriveBytes which implements PBKDF2. PBKDF2 is defined in the RFC 2898 titled: PKCS #5: Password-Based Cryptography Specification Version 2.0 which you may want to read.

于 2016-01-20T22:44:48.307 回答