本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Certificate2.GetPublicKeyAlgorithm方法的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate2.GetPublicKeyAlgorithm方法的具体用法?C# X509Certificate2.GetPublicKeyAlgorithm怎么用?C# X509Certificate2.GetPublicKeyAlgorithm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.X509Certificates.X509Certificate2
的用法示例。
在下文中一共展示了X509Certificate2.GetPublicKeyAlgorithm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifySmevRequestSignature
private static bool VerifySmevRequestSignature(XmlDocument signedSmevRequest)
{
// Создание подписчика XML-документа
var signedXml = new GostSignedXml(signedSmevRequest) { GetIdElementHandler = GetSmevIdElement };
// Поиск узла с подписью
var nodeList = signedSmevRequest.GetElementsByTagName("Signature", SignedXml.XmlDsigNamespaceUrl);
// Загрузка найденной подписи
signedXml.LoadXml((XmlElement)nodeList[0]);
// Поиск ссылки на BinarySecurityToken
var references = signedXml.KeyInfo.GetXml().GetElementsByTagName("Reference", WsSecurityExtNamespace);
if (references.Count > 0)
{
// Определение ссылки на сертификат (ссылка на узел документа)
var binaryTokenReference = ((XmlElement)references[0]).GetAttribute("URI");
if (!String.IsNullOrEmpty(binaryTokenReference) && binaryTokenReference[0] == '#')
{
// Поиск элемента с закодированным в Base64 сертификатом
var binaryTokenElement = signedXml.GetIdElement(signedSmevRequest, binaryTokenReference.Substring(1));
if (binaryTokenElement != null)
{
// Загрузка сертификата, который был использован для подписи
var signingCertificate = new X509Certificate2(Convert.FromBase64String(binaryTokenElement.InnerText));
// Проверка подписи
return signedXml.CheckSignature(signingCertificate.GetPublicKeyAlgorithm());
}
}
}
return false;
}
示例2: Encrypt
public new EncryptedData Encrypt(XmlElement element, X509Certificate2 certificate)
{
if (element == null)
{
return base.Encrypt(element, certificate);
}
if (certificate == null)
{
return base.Encrypt(element, certificate);
}
if (!string.Equals(certificate.PublicKey.Oid.Value, GostCryptoConfig.DefaultSignOid, StringComparison.OrdinalIgnoreCase))
{
return base.Encrypt(element, certificate);
}
var encryptedKey = new EncryptedKey
{
EncryptionMethod = new EncryptionMethod(GostEncryptedXml.XmlEncGostKeyTransportUrl)
};
encryptedKey.KeyInfo.AddClause(new KeyInfoX509Data(certificate));
var encriptionKey = new Gost28147SymmetricAlgorithm();
var publicKey = certificate.GetPublicKeyAlgorithm();
encryptedKey.CipherData.CipherValue = EncryptKey(encriptionKey, publicKey as Gost3410AsymmetricAlgorithmBase);
var encryptedData = new EncryptedData
{
Type = XmlEncElementUrl,
EncryptionMethod = new EncryptionMethod(GostEncryptedXml.XmlEncGost28147Url)
};
encryptedData.KeyInfo.AddClause(new KeyInfoEncryptedKey(encryptedKey));
encryptedData.CipherData.CipherValue = EncryptData(element, encriptionKey, false);
return encryptedData;
}