From: http://www.dup2.org/node/1096
Recently, there was a project involving cooperation with other websites. The authentication plan for communication between the two parties was implemented through RSA. Because it may involve different development environments, we need to study the support for RSA in different languages.
OpenSSL creates a public key file in PEM format by default, but the Java API import password can only be der
Format, especially the key must be encoded with PKCS #8. This requires converting the files generated by OpenSSL.
-
- OpenSSL RSA-inform PEM-In rs1_v. pem-outform der-pubout-out rsapub. Der
- OpenSSL pkcs8-topk8-inform PEM-In rs1_v. pem-outform der-nocrypt-out rs1_v. Der
- The basic algorithm standards are OpenSSL: rsa_private_encrypt/rsa_public_decrypt, rsa_public_encrypt/rsa_private_decrypt, because the OpenSSL module of PHP only provides these four basic functions (do not imagine using something other than the OpenSSL module for RSA operations, such
Pear's crypt_rsa slows down to a terrible level)
- Note that in the above four functions, the padding parameter can be used only a few. Corresponding to cipher in Java. the getinstance () parameter can only use "RSA/NONE/pkcs1padding" or "RSA/NONE/nopadding" (or "RSA/NONE/oaeppadding" corresponds to rsa_pkcs1_oaep_padding, but I did not go into it ). The default padding in PHP is rsa_pkcs1_padding.
- About python... Well, just use ctypes.
- When using RSA signature, the text is first used as a one-way hash, and then the private key is used to encrypt the signature. The verification end obtains the signature and text, decrypts the signature with the public key, and compares whether the text hash is used. OpenSSL encapsulates rsa_sign/rsa_verify to do this.
- However, several NID hashing algorithms of OpenSSL and the standard sha1/MD5 Algorithm seem to be different, and PHP is almost unable to interoperate with these two functions.
- Signature. getinstance () can use "md2withrsa", "md5withrsa", or "sha1withrsa ", however, it is unclear whether it can be used with nid_md2/digest, nid_md5/digest/nid_md5withrsa, nid_sha1/nid_sha1withrsaencryption/nid_sha1withrsa of OpenSSL.
It still takes time for verification.
To improve the interoperability of multiple languages, we do not use the encapsulated functions rsa_sign/rsa_verify.