/// <summary>///[email protected]/// </summary>Public classmyRAs {/// <summary> ///RAS Encryption/// </summary> /// <param name= "Xmlpublickey" >Public Key</param> /// <param name= "encryptstring" >plaintext</param> /// <returns>Ciphertext</returns> Public Static stringRsaencrypt (stringXmlpublickey,stringencryptstring) { byte[] plaintextbarray; byte[] cyphertextbarray; stringresult=String.Empty; System.Security.Cryptography.RSACryptoServiceProvider RSA=NewRSACryptoServiceProvider (); Rsa. Fromxmlstring (Xmlpublickey); intT = (int) (Math.ceiling (Double) Encryptstring.length/(Double) -)); //Split PlainText for(inti =0; I <= t1; i++) {Plaintextbarray= (NewUnicodeEncoding ()). GetBytes (encryptstring.substring (i * -, Encryptstring.length-(I * -) > -? -: Encryptstring.length-(I * -))); Cyphertextbarray= RSA. Encrypt (Plaintextbarray,false); Result+ = Convert.tobase64string (Cyphertextbarray) +"Thisissplit"; } returnResult; } /// <summary> ///RAS Decryption/// </summary> /// <param name= "Xmlprivatekey" >private Key</param> /// <param name= "decryptstring" >Ciphertext</param> /// <returns>plaintext</returns> Public Static stringRsadecrypt (stringXmlprivatekey,stringdecryptstring) { byte[] plaintextbarray; byte[] dyphertextbarray; stringresult=String.Empty; System.Security.Cryptography.RSACryptoServiceProvider RSA=NewRSACryptoServiceProvider (); Rsa. Fromxmlstring (Xmlprivatekey); string[] Split =New string[1]; split[0] ="Thisissplit"; //Split cipher string[] mis =decryptstring.split (Split, stringsplitoptions.removeemptyentries); for(inti =0; I < MIS. Length; i++) {Plaintextbarray=convert.frombase64string (Mis[i]); Dyphertextbarray= RSA. Decrypt (Plaintextbarray,false); Result+= (Newunicodeencoding ()). GetString (Dyphertextbarray); } returnResult; } /// <summary> ///generate public and private key pairs/// </summary> /// <returns>string[] 0: Private key; 1: Public Key</returns> Public Static string[] Rsakey () {string[] keys =New string[2]; System.Security.Cryptography.RSACryptoServiceProvider RSA=NewRSACryptoServiceProvider (); keys[0] = RSA. Toxmlstring (true); keys[1] = RSA. Toxmlstring (false); returnkeys; } }
C # RAS Asymmetric Encryption class supports long strings