当前位置: 首页>>代码示例>>C#>>正文


C# X509Certificate2.GetPublicKeyAlgorithm方法代码示例

本文整理汇总了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;
        }
开发者ID:kapitanov,项目名称:GostCryptography,代码行数:37,代码来源:SignedXmlSmevTest.cs

示例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;
        }
开发者ID:kapitanov,项目名称:GostCryptography,代码行数:39,代码来源:GostEncryptedXmlImpl.cs


注:本文中的System.Security.Cryptography.X509Certificates.X509Certificate2.GetPublicKeyAlgorithm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。