php aes-128-cbc 和 aes-128 加密有什么区别吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33121619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any difference between aes-128-cbc and aes-128 encryption?
提问by Umair Malik
I want to know if there is any difference between these two encryption methods? I never used these before. My client asked me to use AES-128 encryption but when I google it, it show me "aes-128-cbc", "aes-128-ctr", "aes-256-cbc", or "aes-256-ctr" so I want to know which one I should use that will be like AES-128?
我想知道这两种加密方式有什么区别吗?我以前从未使用过这些。我的客户要求我使用 AES-128 加密,但当我用谷歌搜索时,它显示“aes-128-cbc”、“aes-128-ctr”、“aes-256-cbc”或“aes-256-ctr” “所以我想知道我应该使用哪一种像 AES-128 那样?
reference link : this is where I have to send encryption method
参考链接:这是我必须发送加密方法的地方
回答by vish4071
3 things:
3件事:
- AES: Advanced Encryption Standard. This is the name of the encryption algorithm (symmetric encryption). Other symmetric encryption algorithms are: DES, 3-DES etc.
- 128: This probably refers to the key size. AES encryption uses 3 key sizes (128bit, 192bit and 256bit). Block size in AES is also 128 bits.
- CBC: This is the mode of encryption that you want. There are number of modes of encryption, which depends on how fast you want your algorithm to work, parallelism and level of security. A few modes are CBC(Cipher Block Chaining), ECB(Electronic Code Book), CFB(Cipher Feed Back), CTR (Counter) etc.
- AES:高级加密标准。这是加密算法(对称加密)的名称。其他对称加密算法有:DES、3-DES等。
- 128:这可能是指密钥大小。AES 加密使用 3 种密钥大小(128 位、192 位和 256 位)。AES 中的块大小也是 128 位。
- CBC:这是您想要的加密模式。有多种加密模式,这取决于您希望算法运行的速度、并行度和安全级别。几种模式是CBC(密码块链接)、ECB(电子码本)、CFB(密码反馈)、CTR(计数器)等。
Now, your client asked you to encrypt using AES-128. So, you should be using AES encryption with 128 bit key size. Any mode you can use will be of your preference. I'd prefer CBC.
现在,您的客户要求您使用 AES-128 进行加密。因此,您应该使用 128 位密钥大小的 AES 加密。您可以使用的任何模式将是您的偏好。我更喜欢CBC。
回答by Vincent
Just a quick note on CBC vs ECB. When you encrypt using ECB, every 128 bit (depending on the block size) of data gets encrypted with the same key. If there is any pattern in the plaintext, the resulting encrypted text will also be predictable, no matter how good the encryption algorithm is.
只是关于 CBC 与 ECB 的快速说明。当您使用 ECB 进行加密时,每 128 位(取决于块大小)的数据都会使用相同的密钥进行加密。如果明文中有任何模式,那么生成的密文也将是可预测的,无论加密算法有多好。
ECB:
欧洲央行:
Plain text: aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa
---------------- ---------------- ----------------
Encrypted: bdefjakjapqeiowp bdefjakjapqeiowp bdefjakjapqeiowp
If you use CBC, the first block gets XOR'd with the IV (initialization vector) and encrypted with the key and the second block gets XOR'd with the first block and then encrypted with the key, the third with the second. The resulting cipher is then less vulnerable to frequency analysis.
如果您使用 CBC,则第一个块与 IV(初始化向量)进行异或并使用密钥加密,第二个块与第一个块进行异或,然后使用密钥加密,第三个与第二个块进行异或。由此产生的密码不易受到频率分析的影响。
This image is taken from Wikimedia Commons, the free media repository
The disadvantage is that you cannot parallelize the encryption/decryption since you need the result of the previous block, so it may be slower. But in practice, it makes no real difference.
缺点是你不能并行化加密/解密,因为你需要前一个块的结果,所以它可能会更慢。但在实践中,它没有真正的区别。
回答by rossum
Looking at the link you included, it says it will accept a number of different modes, including CBC. Unless you have a specific reason not to use it, then use AES-128-CBC. CBC mode is a good general-purpose mode. You will also need to understand the use of padding (use PKCS#5 or PKCS#7, whatever one your system allows) and an Initialisation Vector, IV, in order for CBC mode to work correctly.
查看您包含的链接,它说它将接受多种不同的模式,包括 CBC。除非您有特定原因不使用它,否则请使用 AES-128-CBC。CBC 模式是一种很好的通用模式。您还需要了解填充的使用(使用 PKCS#5 或 PKCS#7,无论您的系统允许使用哪种)和初始化向量 IV,以便 CBC 模式正常工作。
Do not use ECB mode, since it is insecure and leaks information.
不要使用 ECB 模式,因为它不安全并且会泄露信息。
回答by Raghu Veera
Here aes-128-cbc
and aes-128
. aes
stands for advanced encryption service, 128
is the bit rate, and CBC
is the mode of encryption.
这里aes-128-cbc
和aes-128
。aes
代表高级加密服务,128
是比特率,CBC
是加密方式。
However, this is recited and used only in OPEN SSL
Formats. Prior to Open SSL, PHP used mcrypt_encrypt
which was not properly designed (older versions of PHP).
aes-128
can also be reffered to as rijndael
while using mcrypt
.
但是,这仅在OPEN SSL
格式中被引用和使用。在 Open SSL 之前,PHP 使用的mcrypt_encrypt
设计不当(旧版本的 PHP)。
aes-128
也可以称为rijndael
使用时mcrypt
。