Using. NET-brought RSA, you need to reference System.Security.Cryptography
Test environment. net4.6
Static voidMain (string[] args) { varRSA =NewRSACryptoServiceProvider (); varPublickkey = RSA. Toxmlstring (false); varPrivatekey = RSA. Toxmlstring (true); varPublickeyrsa =NewRSACryptoServiceProvider (); Publickeyrsa.fromxmlstring (Publickkey); varPrivatekeyrsa =NewRSACryptoServiceProvider (); Privatekeyrsa.fromxmlstring (Privatekey); varEncryptbytes = Publickeyrsa.encrypt (Encoding.Default.GetBytes ("Hellow World"),false); stringTMP =""; for(inti =0; i < encryptbytes.length; i++) {tmp+ = Encryptbytes[i] +","; } tmp= tmp. TrimEnd (','); Console.WriteLine (TMP); varSign = Privatekeyrsa.signdata (Encryptbytes,"SHA1"); if(Publickeyrsa.verifydata (Encryptbytes,"SHA1", sign)) { varDecryptbytes = Privatekeyrsa.decrypt (Encryptbytes,false); varstr =Encoding.Default.GetString (decryptbytes); Console.WriteLine (str); } Else{Console.WriteLine ("Sign error!"); } console.read ();}
Run Print:
104,205,171, the, A,206,Panax Notoginseng,127, the,195, Max,236,162, in,144,253, +,197,173, $, the, -,223, *,186,212,218, -, -, -,144,133,174, the, About, -, A, the, the, Wu,214,231, -,191, -, -,102,103, the, -,231, -,171,129,0,165, -,147, A, the, the, the, the,212, the,118, the, -5, $, One, the,241, About,161,218, One, +,179, the,167,141, -,2,188,169,102,222,133,Panax Notoginseng,191, A, -,246, -,238,164, the, Wu,238,126,6, $, About,197,208,164,197,209,98, the,243, the,1 $, the, -,223,234,175, the,5, -,198,169,206, the, -,235,6Hellow World
Test Demo for RSA encryption