1 /// <summary>2 ///RSA public Key Cryptography3 /// </summary>4 /// <param name= "Content" >Text to encrypt</param>5 /// <param name= "PublicKey" >RSA Public Key</param>6 /// <returns></returns>7 Public Static stringRsaencrypt (stringContentstringPublicKey)8 {9 stringresult ="";Ten Try One { ARsacryptoserviceprovider.usemachinekeystore =true;//prevents the specified file error from being found -RSACryptoServiceProvider RSA =NewRSACryptoServiceProvider (); -RSAParameters Rsakeyinfo =NewRSAParameters (); the byte[] Bytearr =convert.frombase64string (publickey); -Rsakeyinfo.modulus = Bytearr. ToList (). GetRange ( in, Bytearr. Length- the). ToArray (); -Rsakeyinfo.exponent = convert.frombase64string ("Aqab"); - RSA. ImportParameters (rsakeyinfo); + byte[] bytes = RSA. Encrypt (UTF8Encoding.UTF8.GetBytes (content),false); -result =convert.tobase64string (bytes); + } A Catch(Exception ex) at { -Log. Warn ("RSA encryption error, encrypted text:"+ content +", encrypt the public key:"+ PublicKey +", error message:"+Ex. Message); - } - returnresult; -}
RSA Public Key Cryptography