提交当前本机整理版本
This commit is contained in:
@@ -14,4 +14,26 @@ namespace Lskj.QueryEssentialInfo
|
||||
public static byte[] Encrypt(string plainText, string publicKeyXml)
|
||||
{
|
||||
byte[] dataToEncrypt = Encoding.UTF8.GetBytes(plainText);
|
||||
using (RSACryptoServi
|
||||
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
|
||||
{
|
||||
rsa.FromXmlString(publicKeyXml);
|
||||
// 默认使用PKCS#1 v1.5填充,4.0版本不支持OAEP-SHA256,只能用OAEP-SHA1,且需要指定true
|
||||
return rsa.Encrypt(dataToEncrypt, false);
|
||||
}
|
||||
}
|
||||
public static string ToXmlPublicKey(string pubilcKey)
|
||||
{
|
||||
RsaKeyParameters rsaKeyParameters = PublicKeyFactory.CreateKey(Convert.FromBase64String(pubilcKey)) as RsaKeyParameters;
|
||||
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
|
||||
{
|
||||
RSAParameters rsaParams = new RSAParameters
|
||||
{
|
||||
Modulus = rsaKeyParameters.Modulus.ToByteArrayUnsigned(),
|
||||
Exponent = rsaKeyParameters.Exponent.ToByteArrayUnsigned()
|
||||
};
|
||||
rsa.ImportParameters(rsaParams);
|
||||
return rsa.ToXmlString(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user