RSA key cross-platform common

Source: Internet
Author: User
Tags openssl x509

RSA uses public key encryption, decryption with private key (signature instead, using private key signature, with public key to verify the signature). For example, I and partner D between the data transfer, I use D provided to my public key to encrypt, passed to D, he uses his private key to decrypt the original text, response, d Use the public key I provided to his encryption, I have received the original text using my private key decryption. A common scenario is that the data transfer between the two parties uses AES encryption and then encrypts the AES key through RSA. (Aes has higher performance than RSA).

With regard to the generation of keys, the common OpenSSL generation under Linux can also be generated using the methods provided by the specific language platform.

//C # version (parameter false generates the private key, public generates the key)
RSACryptoServiceProvider RSA =NewRSACryptoServiceProvider ();
Rsa. Exportparameters (false);//the image
Rsa. Exportcspblob (false);//string
Rsa. Toxmlstring (false);//XML Format

#python version
ImportRsa

(PubKey, Privkey) = Rsa.newkeys (1024)

Pub = PUBKEY.SAVE_PKCS1 ()#Public Key
pri = PRIVKEY.SAVE_PKCS1 ()#private Key

You can also use openssl.net generation, which is an implementation of OpenSSL on. Net. There is a CLI project that can be run under the command line, and he should generate consistent with the use of OpenSSL generated under Linux.

Genrsa-out RSA_PRIVATE_KEY.PEM 1024
RSA-inchRsa_private_key.pem-pubout-out Rsa_public_key.pem


However, the RSA key between each platform language cannot be generalized, the C # generated Java,python cannot be used, and the C # that OpenSSL generates cannot be used, exception information: Incorrect provider version

Using openssl.net encryption decryption in. NET is a good choice if you use the key generated by OpenSSL. Another option is to convert the key into the desired format for the respective language, such as this Http://csslab.s3.amazonaws.com/csslabs/Siva/opensslkey.cs

You can convert OpenSSL key to the XML format required by C # so that you can decrypt RSA encryption directly using the methods in the. NET Framework.

Sometimes the partner gives you may not be a public key, and a CERT certificate file, which will need to extract the public key from this certificate

#under Linux, extract via OpenSSL
OpenSSL X509-inchCa.crt-pubkey

RSA key cross-platform common

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.