相关资料
https://en.wikipedia.org/wiki/Public-key_cryptography
https://en.wikipedia.org/wiki/Digital_signature
# man genrsa
# man rsa
# man pkcs8
# man dgst
公钥加密:public key encryption
Public-key cryptography, or asymmetric cryptography, is a cryptographic system that uses pairs of keys: public keys which may be disseminated widely, and private keys which are known only to the owner.
This accomplishes two functions: authentication, which is when the public key is used to verify that a holder of the paired private key sent the message, and encryption, whereby only the holder of the paired private key can decrypt the message encrypted with the public key.
RSA
RSA 算法规定:
明文长度不能超过密钥长度 - 11(单位:字节)。
密文长度正好等于密钥长度。
如果密钥长度为1024位,则:
明文长度最大为117字节。
密文长度为128字节。
genrsa
The genrsa command generates an RSA private key.
rsa
The rsa command processes RSA keys. They can be converted between various forms and their components printed out.
pkcs8
The pkcs8 command processes private keys in PKCS#8 format.
# openssl genrsa -out rsa_private_key.pem 1024 // 生成 RSA 私钥
# openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem // 生成 RSA 公钥
# openssl pkcs8 -topk8 -in rsa_private_key.pem -nocrypt -out pkcs8_private_key.pem // 将 RSA 私钥转换成 PKCS8 格式
# openssl rsa -in rsa_private_key.pem -noout -text // 查看私钥明细
# openssl rsa -in rsa_public_key.pem -pubin -noout -text // 查看公钥明细
公钥加密(Public Key Encryption
)
Public key encryption, in which a message is encrypted with a recipient's public key. The message cannot be decrypted by anyone who does not possess the matching private key.
公钥加密,私钥解密。
# openssl rsautl -encrypt -in test.txt -out test.enc -inkey rsa_public_key.pem -pubin // 公钥加密
# openssl rsautl -decrypt -in test.enc -out test.dec -inkey rsa_private_key.pem // 私钥解密
数字签名(Digital signature
)
A digital signature is a mathematical scheme for verifying the authenticity of digital messages or documents.
A valid digital signature gives a recipient very strong reason to believe that the message was created by a known sender (authentication), that the sender cannot deny having sent the message (non-repudiation), and that the message was not altered in transit (integrity).
私钥签名,公钥验证。
# openssl rsautl -sign -in test.txt -inkey rsa_private_key.pem -out test.sign // 私钥签名
# openssl rsautl -verify -in test.sign -inkey rsa_public_key.pem -pubin // 公钥验证
散列签名
签名方案用于消息的散列值,而不是消息本身。
# openssl dgst -sign rsa_private_key.pem -sha1 -out test.sign test.txt
# openssl dgst -verify rsa_public_key.pem -sha1 -signature test.sign test.txt
博主真是太厉害了!!!
看的我热血沸腾啊https://www.237fa.com/
想想你的文章写的特别好https://www.ea55.com/
真棒!