C# RSA加密

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

byte[] cipherbytes;

RsaKeyParameters publickeyParam = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(spk));//spk为公钥

string XML = string.Format("<RSAKeyValue><Modulus>{0]</Modulus><Exponent>{1}</Exponent><RSAKeyValue>",

Convert.ToBase64String(publicKeyParam.Modulus.ToByteArrayUnsigned()),

Convert.ToBase64String(publicKeyParam.Exponent.ToByteArrayUnsigned()));

rsa.FromXmlString(XML);

cipherbytes = rsa.Encrypt(Encoding.UTF8.GetBytes(userid),false);//userid为加密内容

string data = Convert.ToBase64String(cipherbytes);//加密后参数

posted @ 2023-07-31 18:29  以至千里  阅读(179)  评论(0)    收藏  举报