简体   繁体   English

RijndaelManaged密钥长度是否与AES [key length]相同?

[英]Is RijndaelManaged key length the same as AES[key length]?

RijndaelManaged is an algorithm while AES is the standard. RijndaelManaged是一种算法,而AES是标准算法。 When referring to AES256, does that mean the key length I'm using with RijndaelManaged must be 256 characters? 当提到AES256时,这是否意味着我与RijndaelManaged一起使用的密钥长度必须为256个字符?

If I have a key like this: 如果我有这样的钥匙:

key = "mytestkey";

which is only 9 characters, does that mean I'm using AES9? 只有9个字符,这表示我正在使用AES9吗?

Aes/Rijndael key sizes are in bits, not characters; Aes / Rijndael密钥大小以位为单位,而不是字符; AES256 uses a 256-bit key. AES256使用256位密钥。 You must give it a key that is exactly 256 bits. 您必须给它一个正好为256位的密钥。 The AES standard and Rijndael only accept key sizes that are either 128, 192, or 256 bits. AES标准和Rijndael仅接受128、192或256位的密钥大小。

You should not interchange AES and Rijndael. 您不应该互换AES和Rijndael。 The AES standard is derived from Rijndael, but they are not exactly the same. AES标准源自Rijndael,但它们并不完全相同。 If you wish to use AES, use AES for all operations; 如果您希望使用AES,请对所有操作使用AES; if you wish to use Rijndael, use Rijndael for all operations. 如果您想使用Rijndael,请对所有操作使用Rijndael。

"mytestkey" cannot directly be a key to AES256 nor a similar Rijndael mode; "mytestkey"不能直接是AES256的密钥,也不可以是类似的Rijndael模式。 it is not 256 bits long. 它不是256位长。 In order to use it as a key, you'll have to transform it into a block of bytes that is 256 bits long. 为了将其用作键,您必须将其转换为256位长的字节块。

If you're working with passwords, one typical means to do this is with key stretching , using hash algorithms such as PBKDF2 or Scrypt . 如果您使用的是密码,一种典型的方法是使用PBKDF2Scrypt之类的哈希算法进行密钥扩展 PBKDF stands for "Password-based key derivation function", which is basically exactly what you're doing - deriving a key from a password. PBKDF代表“基于密码的密钥派生功能”,它基本上就是您要做的-从密码派生密钥。

Theoretically you could also just hash the password with SHA256 (which always has a 256-bit output) and use that 256-bit block as the key to AES; 从理论上讲,您也可以使用SHA256(始终具有256位输出)对密码进行哈希处理,并使用该256位块作为AES的密钥; doing so is unwise from a security standpoint because it is relatively easy to precompute SHA hashes of passwords. 从安全角度来看,这样做是不明智的,因为预先计算密码的SHA哈希值相对容易。

Please keep in mind that if you use a password that has very little entropy, then the security of your encryption suffers - the time it'll take for someone to guess the key could be short. 请记住,如果您使用的密码熵很少,那么加密的安全性就会受到影响-有人猜测密钥可能需要很短的时间。 "mytestkey" has at most ~42 bits of entropy - you're only using lower case letters, so 26 values per place, and there are 9 places (9 characters). "mytestkey"最多具有"mytestkey"位熵-您仅使用小写字母,因此每个位置26个值,并且有9个位置(9个字符)。 Thus the number of bits theoretically needed to stores this is log_2( 26^9 ) = 42.3 . 因此,理论上需要存储的位数是log_2( 26^9 ) = 42.3 In this circumstance, you'd be using AES256 with a key that has only ~42 bits of entropy. 在这种情况下,您将使用仅具有约42位熵的密钥的AES256。

I should note that the advice given here is an incomplete treatment of how to turn passwords into keys, from a security perspective. 我应该注意,从安全角度来看,此处提供的建议对于如何将密码转换为密钥不完整。 If you want to better understand how to properly generate keys from passwords, I suggest you start with some reading such as the Password Storage Cheat Sheet at owasp.org. 如果您想更好地了解如何从密码正确生成密钥,建议您从一些阅读资料开始,例如owasp.org上的密码存储备忘单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM