<aside> 📘 TL;DR; 基于 RSA 的签名与加密算法实现
算法 | PKCS-v15 | PSS | OAEP |
---|---|---|---|
可用于签名 SSA | ✅ | ✅ | ❌ |
可用于加密 ES | ✅ | ❌ | ✅ |
确定性 | ✅ | ❌ | ❌ |
self contained | ✅ | ❌ | ❌ |
虽然 PKCS 更久经考验。但是目前新项目更多推荐使用 PSS 和 OAEP。
注:确定性指的是,每次给予相同的输入,都会产生相同的输出。
注:self contained 是指,产生的结果中已包含了 解密/验签 所需的全部信息。
</aside>
There are two RSA signature schemes specified in [PKCS1]: RSASSA-PKCS1-v1_5
and RSASSA-PSS
(RSASSA = RSA Signature Scheme with Appendix). RSASSA-PSS is a probabilistic signature scheme (PSS) with appendix. A signature scheme with appendix requires the message itself to verify the signature (i.e. the message is not recoverable from the signature).
There are also two RSA encryption schemes: RSAES-PKCS-v1_5
and RSAES-OAEP
(Optimal Asymmetric Encryption Padding). Both use random seeds (and so produce a different ciphertext value each time), but RSA-OAEP is more robust and is the recommended alternative.
How much safer is RSA-OAEP compared to RSA with PKCS#1 v1.5 padding?
The PKCS-V1_5 schemes are "self contained": the signature values and ciphertext values contain all the information needed to verify or decipher. In contrast, both the RSA-PSS and RSA-OAEP schemes require parameters which need to be provided separately. Both require a hash function to be specified and both use a mask generation function (MGF). There is currently only one MGF specified, called MGF1
. This in turn uses a hash function (the "MGF hash function") which may be different from the scheme hash function. More details below.
Incidentally, the terms "function" and "algorithm" are used interchangeably here. The term "algorithm" was used in the early PKCS#1 specifications (and is reflected in the ASN.1 type names), and "function" is used in the more recent ones.
The signature schemes RSASSA-PKCS-v1_5 ("PKCSV1_5") and RSASSA-PSS ("PSS") have differences.