本文整理汇总了C#中System.Security.Cryptography.AsymmetricAlgorithm.ToXmlString方法的典型用法代码示例。如果您正苦于以下问题:C# AsymmetricAlgorithm.ToXmlString方法的具体用法?C# AsymmetricAlgorithm.ToXmlString怎么用?C# AsymmetricAlgorithm.ToXmlString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.AsymmetricAlgorithm
的用法示例。
在下文中一共展示了AsymmetricAlgorithm.ToXmlString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSecretKey
public static byte[] GetSecretKey(EncryptedKey encryptedKey, AsymmetricAlgorithm privateKey)
{
var keyAlgorithm = encryptedKey.EncryptionMethod.KeyAlgorithm;
var asymmetricAlgorithm = GetAsymmetricKeyTransportAlgorithm(keyAlgorithm);
asymmetricAlgorithm.FromXmlString(privateKey.ToXmlString(true));
var useOaep = keyAlgorithm == EncryptedXml.XmlEncRSAOAEPUrl;
return asymmetricAlgorithm.Decrypt(encryptedKey.CipherData.CipherValue, useOaep);
}
示例2: CreateKeyFileForAsymmetricAlgorithm
/// <summary>
/// 为非对称加密生成密钥对,并存储到文件
/// </summary>
/// <param name="asymmetricAlgorithm"></param>
/// <param name="fileName"></param>
/// <param name="isPrivate"></param>
public static void CreateKeyFileForAsymmetricAlgorithm(AsymmetricAlgorithm asymmetricAlgorithm, string fileName, bool isPrivate)
{
if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName");
string content = asymmetricAlgorithm.ToXmlString(isPrivate);
File.WriteAllText(fileName, Convert.ToBase64String(Encoding.UTF8.GetBytes(content)));
}
示例3: CompareAsymmetricAlgorithm
private bool CompareAsymmetricAlgorithm (AsymmetricAlgorithm a1, AsymmetricAlgorithm a2)
{
// fast path
if (a1.KeySize != a2.KeySize)
return false;
// compare public keys - if they match we can assume the private match too
return (a1.ToXmlString (false) == a2.ToXmlString (false));
}