Ser*_*Dom 4 cryptography aes node.js
我遍历了Node.js Crypto文档,但仍然找不到Cipher类使用的默认填充,例如,该方法cipher.setAutoPadding(true)没有相关规范。是PKCS#5,PKCS#7 ...吗?
关于此的任何信息都将很棒!
在文档(https://nodejs.org/api/crypto.html#crypto_cipher_setautopadding_autopadding)中说:
禁用自动填充对于非标准填充非常有用,例如使用0x0代替PKCS填充。
因此,它使用的是“ PKCS”。更具体地说,是PKCS7。
PKCS7定义了与PKCS5相同的填充算法,但是PKCS5假定所有密码都将具有8字节(64位)的块大小。PKCS7的版本将其描述为k字节块。实际上,人们忽略了PKCS5具有固定的块大小,而“ PKCS5填充”和“ PKCS7填充”是同一回事。
PKCS5(https://tools.ietf.org/html/rfc2898#section-6.1.1):
4. Concatenate M and a padding string PS to form an encoded
message EM:
EM = M || PS ,
where the padding string PS consists of 8-(||M|| mod 8) octets
each with value 8-(||M|| mod 8). The padding string PS will
satisfy one of the following statements:
PS = 01, if ||M|| mod 8 = 7 ;
PS = 02 02, if ||M|| mod 8 = 6 ;
...
PS = 08 08 08 08 08 08 08 08, if ||M|| mod 8 = 0.
Run Code Online (Sandbox Code Playgroud)
PKCS7(https://tools.ietf.org/html/rfc5652#section-6.3):
Some content-encryption algorithms assume the input length is a
multiple of k octets, where k is greater than one. For such
algorithms, the input shall be padded at the trailing end with
k-(lth mod k) octets all having value k-(lth mod k), where lth is
the length of the input. In other words, the input is padded at
the trailing end with one of the following strings:
01 -- if lth mod k = k-1
02 02 -- if lth mod k = k-2
.
.
.
k k ... k k -- if lth mod k = 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1170 次 |
| 最近记录: |