任何人都可以告诉我下面的代码段在做什么。我想使用Nodejs来实现这一点。我对 CSharp 完全陌生
此方法 FromXmlString 对于此处的加密真的是必需的吗?请帮忙
public void FromXmlString(RSACryptoServiceProvider rsa, string xmlString)
{
RSAParameters parameters = new RSAParameters();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);
if (xmlDoc.DocumentElement.Name.Equals("RSAKeyValue"))
{
foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
{
switch (node.Name)
{
case "Modulus": parameters.Modulus = Convert.FromBase64String(node.InnerText); break;
case "Exponent": parameters.Exponent = Convert.FromBase64String(node.InnerText); break;
case "P": parameters.P = Convert.FromBase64String(node.InnerText); break;
case "Q": parameters.Q = Convert.FromBase64String(node.InnerText); break;
case "DP": parameters.DP = Convert.FromBase64String(node.InnerText); break;
case "DQ": parameters.DQ = Convert.FromBase64String(node.InnerText); break;
case "InverseQ": parameters.InverseQ = Convert.FromBase64String(node.InnerText); break;
case "D": parameters.D = Convert.FromBase64String(node.InnerText); break;
}
}
}
rsa.ImportParameters(parameters);
}
public string EncryptAsymmetric(string encryptText, string publicKey)
{
bool isOAEP = false;
byte[] byteEncrypt = Encoding.UTF8.GetBytes(encryptText);
byte[] encryptedData;
var RSA = new RSACryptoServiceProvider();
FromXmlString(RSA, publicKey);
encryptedData = RSA.Encrypt(byteEncrypt, isOAEP);
return Convert.ToBase64String(encryptedData);
}
慕桂英3389331
相关分类