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