• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# X509Certificates.PublicKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Security.Cryptography.X509Certificates.PublicKey的典型用法代码示例。如果您正苦于以下问题:C# PublicKey类的具体用法?C# PublicKey怎么用?C# PublicKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PublicKey类属于System.Security.Cryptography.X509Certificates命名空间,在下文中一共展示了PublicKey类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: X509SubjectKeyIdentifierExtension

 public X509SubjectKeyIdentifierExtension(PublicKey key, bool critical)
 {
   Contract.Requires(key.EncodedKeyValue != null);
   Contract.Requires(key.EncodedKeyValue.RawData != null);
   Contract.Requires(key.EncodedParameters != null);
   Contract.Requires(key.EncodedParameters.RawData != null);
   Contract.Ensures(key.EncodedParameters.RawData != null);
 }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:8,代码来源:System.Security.Cryptography.X509Certificates.X509SubjectKeyIdentifierExtension.cs


示例2: Reset

        public override void Reset()
        {
            _lazyRawData = null;
            _lazySignatureAlgorithm = null;
            _lazyVersion = 0;
            _lazySubjectName = null;
            _lazyIssuerName = null;
            _lazyPublicKey = null;
            _lazyPrivateKey = null;
            _lazyExtensions = null;

            base.Reset();
        }
开发者ID:crummel,项目名称:dotnet_corefx,代码行数:13,代码来源:X509Certificate2.cs


示例3: ComputeCapiSha1OfPublicKey

        public byte[] ComputeCapiSha1OfPublicKey(PublicKey key)
        {
            // The CapiSha1 value is the SHA-1 of the SubjectPublicKeyInfo field, inclusive
            // of the DER structural bytes.

            //SubjectPublicKeyInfo::= SEQUENCE {
            //    algorithm AlgorithmIdentifier{ { SupportedAlgorithms} },
            //    subjectPublicKey BIT STRING,
            //    ... }
            //
            //AlgorithmIdentifier{ ALGORITHM: SupportedAlgorithms} ::= SEQUENCE {
            //    algorithm ALGORITHM.&id({ SupportedAlgorithms}),
            //    parameters ALGORITHM.&Type({ SupportedAlgorithms}
            //    { @algorithm}) OPTIONAL,
            //    ... }
            //
            //ALGORITHM::= CLASS {
            //    &Type OPTIONAL,
            //    &id OBJECT IDENTIFIER UNIQUE }
            //WITH SYNTAX {
            //    [&Type]
            //IDENTIFIED BY &id }

            // key.EncodedKeyValue corresponds to SubjectPublicKeyInfo.subjectPublicKey, except it
            // has had the BIT STRING envelope removed.
            //
            // key.EncodedParameters corresponds to AlgorithmIdentifier.Parameters precisely
            // (DER NULL for RSA, DER Constructed SEQUENCE for DSA)

            byte[] empty = Array.Empty<byte>();
            byte[][] algorithmOid = DerEncoder.SegmentedEncodeOid(key.Oid);
            // Because ConstructSegmentedSequence doesn't look to see that it really is tag+length+value (but does check
            // that the array has length 3), just hide the joined TLV triplet in the last element.
            byte[][] segmentedParameters = { empty, empty, key.EncodedParameters.RawData };
            byte[][] algorithmIdentifier = DerEncoder.ConstructSegmentedSequence(algorithmOid, segmentedParameters);
            byte[][] subjectPublicKey = DerEncoder.SegmentedEncodeBitString(key.EncodedKeyValue.RawData);

            using (SHA1 hash = SHA1.Create())
            {
                return hash.ComputeHash(
                    DerEncoder.ConstructSequence(
                        algorithmIdentifier,
                        subjectPublicKey));
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:45,代码来源:OpenSslX509Encoder.cs


示例4: Constructor_Dsa_FromScratch

		public void Constructor_Dsa_FromScratch ()
		{
			// providing Oid for parameters and keyvalue isn't required
			PublicKey pk = new PublicKey (new Oid (dsaOid.Value),
				new AsnEncodedData (dsa_params),
				new AsnEncodedData (dsa_public_key));

			Assert.AreEqual (dsaOid.Value, pk.Oid.Value, "Oid.Value");
			Assert.IsNull (pk.EncodedParameters.Oid, "EncodedParameters.Oid");
			Assert.AreEqual (BitConverter.ToString (dsa_params), BitConverter.ToString (pk.EncodedParameters.RawData), "EncodedParameters.RawData");
			Assert.IsNull (pk.EncodedKeyValue.Oid, "EncodedKeyValue.Oid");
			Assert.AreEqual (BitConverter.ToString (dsa_public_key), BitConverter.ToString (pk.EncodedKeyValue.RawData), "EncodedKeyValue.RawData");
			Assert.AreEqual (dsa_public_key_xml, pk.Key.ToXmlString (false), "Key");
			Assert.IsTrue ((pk.Key as DSACryptoServiceProvider).PublicOnly, "Key.PublicOnly");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:15,代码来源:PublicKeyTest.cs


示例5: ExportPublicKey

        private static byte[] ExportPublicKey(PublicKey key)
        {
            // From: http://pstaev.blogspot.fr/2010/08/convert-rsa-public-key-from-xml-to-pem.html

            byte[] oid = { 0x30, 0xD, 0x6, 0x9, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0xD, 0x1, 0x1, 0x1, 0x5, 0x0 }; // Object ID for RSA

            //Transform the public key to PEM Base64 Format
            List<byte> binaryPublicKey = key.EncodedKeyValue.RawData.ToList();
            binaryPublicKey.Insert(0, 0x0); // Add NULL value

            CalculateAndAppendLength(ref binaryPublicKey);

            binaryPublicKey.Insert(0, 0x3);
            binaryPublicKey.InsertRange(0, oid);

            CalculateAndAppendLength(ref binaryPublicKey);

            binaryPublicKey.Insert(0, 0x30);
            return binaryPublicKey.ToArray();
        }
开发者ID:modulexcite,项目名称:ShareX_Google_Code,代码行数:20,代码来源:Jira.cs


示例6: X509SubjectKeyIdentifierExtension

 public X509SubjectKeyIdentifierExtension(PublicKey key, bool critical)
     : this(key, X509SubjectKeyIdentifierHashAlgorithm.Sha1, critical)
 {
 }
开发者ID:dotnet,项目名称:corefx,代码行数:4,代码来源:X509SubjectKeyIdentifierExtension.cs


示例7: EncodeExtension

        private static byte[] EncodeExtension(PublicKey key, X509SubjectKeyIdentifierHashAlgorithm algorithm)
        {
            if (key == null)
                throw new ArgumentNullException(nameof(key));

            byte[] subjectKeyIdentifier = GenerateSubjectKeyIdentifierFromPublicKey(key, algorithm);
            return EncodeExtension(subjectKeyIdentifier);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:X509SubjectKeyIdentifierExtension.cs


示例8: EncodePublicKey

        // Construct CERT_PUBLIC_KEY_INFO2 in unmanged memory from given encoded blobs.
        private static unsafe SafeLocalAllocHandle EncodePublicKey (PublicKey key) {
            SafeLocalAllocHandle publicKeyInfo = SafeLocalAllocHandle.InvalidHandle;
            CAPI.CERT_PUBLIC_KEY_INFO2 * pPublicKeyInfo = null;
            string objId = key.Oid.Value;
            byte[] encodedParameters = key.EncodedParameters.RawData;
            byte[] encodedKeyValue = key.EncodedKeyValue.RawData;

            uint cbPublicKeyInfo = (uint) (Marshal.SizeOf(typeof(CAPI.CERT_PUBLIC_KEY_INFO2)) + 
                                                          X509Utils.AlignedLength((uint) (objId.Length + 1)) + 
                                                          X509Utils.AlignedLength((uint) encodedParameters.Length) +
                                                          encodedKeyValue.Length);

            publicKeyInfo = CAPI.LocalAlloc(CAPI.LPTR, new IntPtr(cbPublicKeyInfo));
            pPublicKeyInfo = (CAPI.CERT_PUBLIC_KEY_INFO2 *) publicKeyInfo.DangerousGetHandle();
            IntPtr pszObjId =  new IntPtr((long) pPublicKeyInfo + Marshal.SizeOf(typeof(CAPI.CERT_PUBLIC_KEY_INFO2)));
            IntPtr pbParameters = new IntPtr((long) pszObjId + X509Utils.AlignedLength(((uint) (objId.Length + 1))));
            IntPtr pbPublicKey = new IntPtr((long) pbParameters + X509Utils.AlignedLength((uint) encodedParameters.Length));

            pPublicKeyInfo->Algorithm.pszObjId = pszObjId;
            byte[] szObjId = new byte[objId.Length + 1];
            Encoding.ASCII.GetBytes(objId, 0, objId.Length, szObjId, 0);
            Marshal.Copy(szObjId, 0, pszObjId, szObjId.Length);
            if (encodedParameters.Length > 0) {
                pPublicKeyInfo->Algorithm.Parameters.cbData = (uint) encodedParameters.Length;
                pPublicKeyInfo->Algorithm.Parameters.pbData = pbParameters;
                Marshal.Copy(encodedParameters, 0, pbParameters, encodedParameters.Length);
            }
            pPublicKeyInfo->PublicKey.cbData = (uint) encodedKeyValue.Length;
            pPublicKeyInfo->PublicKey.pbData = pbPublicKey;
            Marshal.Copy(encodedKeyValue, 0, pbPublicKey, encodedKeyValue.Length);
            return publicKeyInfo;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:33,代码来源:X509Extension.cs


示例9: Constructor_Dsa_UnknownOid_Key

		public void Constructor_Dsa_UnknownOid_Key ()
		{
			// providing Oid for parameters and keyvalue isn't required
			PublicKey pk = new PublicKey (new Oid (unknownOid.Value),
				new AsnEncodedData (dsa_params),
				new AsnEncodedData (dsa_public_key));

			Assert.AreEqual (dsa_public_key_xml, pk.Key.ToXmlString (false), "Key");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:PublicKeyTest.cs


示例10: Constructor_Dsa_UnknownOid

		public void Constructor_Dsa_UnknownOid ()
		{
			// providing Oid for parameters and keyvalue isn't required
			PublicKey pk = new PublicKey (new Oid (unknownOid.Value),
				new AsnEncodedData (dsa_params),
				new AsnEncodedData (dsa_public_key));

			Assert.AreEqual (unknownOid.Value, pk.Oid.Value, "Oid.Value");
			Assert.IsNull (pk.EncodedParameters.Oid, "EncodedParameters.Oid");
			Assert.AreEqual (BitConverter.ToString (dsa_params), BitConverter.ToString (pk.EncodedParameters.RawData), "EncodedParameters.RawData");
			Assert.IsNull (pk.EncodedKeyValue.Oid, "EncodedKeyValue.Oid");
			Assert.AreEqual (BitConverter.ToString (dsa_public_key), BitConverter.ToString (pk.EncodedKeyValue.RawData), "EncodedKeyValue.RawData");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:13,代码来源:PublicKeyTest.cs


示例11: Constructor_Dsa_WeirdParameters_Key

		public void Constructor_Dsa_WeirdParameters_Key ()
		{
			PublicKey pk = new PublicKey (new Oid (dsaOid.Value),
				new AsnEncodedData (new byte[16] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }),
				new AsnEncodedData (dsa_public_key));

			Assert.AreEqual (dsa_public_key_xml, pk.Key.ToXmlString (false), "Key");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:PublicKeyTest.cs


示例12: Constructor_Dsa_WeirdParameters

		public void Constructor_Dsa_WeirdParameters ()
		{
			PublicKey pk = new PublicKey (new Oid (dsaOid.Value),
				new AsnEncodedData (new byte[16] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }),
				new AsnEncodedData (dsa_public_key));

			Assert.AreEqual (dsaOid.Value, pk.Oid.Value, "Oid.Value");
			Assert.IsNull (pk.EncodedParameters.Oid, "EncodedParameters.Oid");
			Assert.AreEqual ("00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F", BitConverter.ToString (pk.EncodedParameters.RawData), "EncodedParameters.RawData");
			Assert.IsNull (pk.EncodedKeyValue.Oid, "EncodedKeyValue.Oid");
			Assert.AreEqual (BitConverter.ToString (dsa_public_key), BitConverter.ToString (pk.EncodedKeyValue.RawData), "EncodedKeyValue.RawData");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:PublicKeyTest.cs


示例13: Constructor_Dsa_EmptyParameters_Key

		public void Constructor_Dsa_EmptyParameters_Key ()
		{
			PublicKey pk = new PublicKey (new Oid (dsaOid.Value),
				new AsnEncodedData (new byte[0]), // same as NULL (0x05, 0x00)
				new AsnEncodedData (dsa_public_key));

			Assert.AreEqual (dsa_public_key_xml, pk.Key.ToXmlString (false), "Key");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:PublicKeyTest.cs


示例14: Constructor_Dsa_EmptyParameters

		public void Constructor_Dsa_EmptyParameters ()
		{
			PublicKey pk = new PublicKey (new Oid (dsaOid.Value),
				new AsnEncodedData (new byte[0]), // same as NULL (0x05, 0x00)
				new AsnEncodedData (dsa_public_key));

			Assert.AreEqual (dsaOid.Value, pk.Oid.Value, "Oid.Value");
			Assert.IsNull (pk.EncodedParameters.Oid, "EncodedParameters.Oid");
			Assert.AreEqual (String.Empty, BitConverter.ToString (pk.EncodedParameters.RawData), "EncodedParameters.RawData");
			Assert.IsNull (pk.EncodedKeyValue.Oid, "EncodedKeyValue.Oid");
			Assert.AreEqual (BitConverter.ToString (dsa_public_key), BitConverter.ToString (pk.EncodedKeyValue.RawData), "EncodedKeyValue.RawData");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:PublicKeyTest.cs


示例15: X509SubjectKeyIdentifierExtension

		public X509SubjectKeyIdentifierExtension (PublicKey key, X509SubjectKeyIdentifierHashAlgorithm algorithm, bool critical)
		{
			if (key == null)
				throw new ArgumentNullException ("key");

			byte[] pkraw = key.EncodedKeyValue.RawData;
			// compute SKI
			switch (algorithm) {
			// hash of the public key, excluding Tag, Length and unused bits values
			case X509SubjectKeyIdentifierHashAlgorithm.Sha1:
				_subjectKeyIdentifier = SHA1.Create ().ComputeHash (pkraw);
				break;
			// 0100 bit pattern followed by the 60 last bit of the hash
			case X509SubjectKeyIdentifierHashAlgorithm.ShortSha1:
				byte[] hash = SHA1.Create ().ComputeHash (pkraw);
				_subjectKeyIdentifier = new byte [8];
				Buffer.BlockCopy (hash, 12, _subjectKeyIdentifier, 0, 8);
				_subjectKeyIdentifier [0] = (byte) (0x40 | (_subjectKeyIdentifier [0] & 0x0F));
				break;
			// hash of the public key, including Tag, Length and unused bits values
			case X509SubjectKeyIdentifierHashAlgorithm.CapiSha1:
				// CryptoAPI does that hash on the complete subjectPublicKeyInfo (unlike PKIX)
				// http://groups.google.ca/groups?selm=e7RqM%24plCHA.1488%40tkmsftngp02&oe=UTF-8&output=gplain
				ASN1 subjectPublicKeyInfo = new ASN1 (0x30);
				ASN1 algo = subjectPublicKeyInfo.Add (new ASN1 (0x30));
				algo.Add (new ASN1 (CryptoConfig.EncodeOID (key.Oid.Value)));
				algo.Add (new ASN1 (key.EncodedParameters.RawData)); 
				// add an extra byte for the unused bits (none)
				byte[] full = new byte [pkraw.Length + 1];
				Buffer.BlockCopy (pkraw, 0, full, 1, pkraw.Length);
				subjectPublicKeyInfo.Add (new ASN1 (0x03, full));
				_subjectKeyIdentifier = SHA1.Create ().ComputeHash (subjectPublicKeyInfo.GetBytes ());
				break;
			default:
				throw new ArgumentException ("algorithm");
			}

			_oid = new Oid (oid, friendlyName);
			base.Critical = critical;
			RawData = Encode ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:41,代码来源:X509SubjectKeyIdentifierExtension.cs


示例16: FixtureSetUp

		public void FixtureSetUp ()
		{
			pk1 = new X509Certificate2 (Encoding.ASCII.GetBytes (X509Certificate2Test.base64_cert)).PublicKey;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:4,代码来源:X509SubjectKeyIdentifierExtensionTest.cs


示例17: X509SubjectKeyIdentifierExtension

 public X509SubjectKeyIdentifierExtension (PublicKey key, X509SubjectKeyIdentifierHashAlgorithm algorithm, bool critical) :
     base (CAPI.szOID_SUBJECT_KEY_IDENTIFIER, EncodePublicKey(key, algorithm), critical) {}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:2,代码来源:X509Extension.cs


示例18: ComputeCapiSha1OfPublicKey

        public byte[] ComputeCapiSha1OfPublicKey(PublicKey key)
        {
            unsafe
            {
                fixed (byte* pszOidValue = key.Oid.ValueAsAscii())
                {
                    byte[] encodedParameters = key.EncodedParameters.RawData;
                    fixed (byte* pEncodedParameters = encodedParameters)
                    {
                        byte[] encodedKeyValue = key.EncodedKeyValue.RawData;
                        fixed (byte* pEncodedKeyValue = encodedKeyValue)
                        {
                            CERT_PUBLIC_KEY_INFO publicKeyInfo = new CERT_PUBLIC_KEY_INFO()
                            {
                                Algorithm = new CRYPT_ALGORITHM_IDENTIFIER()
                                {
                                    pszObjId = new IntPtr(pszOidValue),
                                    Parameters = new CRYPTOAPI_BLOB(encodedParameters.Length, pEncodedParameters),
                                },

                                PublicKey = new CRYPT_BIT_BLOB()
                                {
                                    cbData = encodedKeyValue.Length,
                                    pbData = pEncodedKeyValue,
                                    cUnusedBits = 0,
                                },
                            };

                            int cb = 20;
                            byte[] buffer = new byte[cb];
                            if (!Interop.crypt32.CryptHashPublicKeyInfo(IntPtr.Zero, AlgId.CALG_SHA1, 0, CertEncodingType.All, ref publicKeyInfo, buffer, ref cb))
                                throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;
                            if (cb < buffer.Length)
                            {
                                byte[] newBuffer = new byte[cb];
                                Array.Copy(buffer, 0, newBuffer, 0, cb);
                                buffer = newBuffer;
                            }
                            return buffer;
                        }
                    }
                }
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:44,代码来源:X509Pal.CustomExtensions.cs


示例19: PublicKey

 internal PublicKey (PublicKey publicKey) {
     m_oid = new Oid(publicKey.m_oid);
     m_encodedParameters = new AsnEncodedData(publicKey.m_encodedParameters);
     m_encodedKeyValue = new AsnEncodedData(publicKey.m_encodedKeyValue);
 }
开发者ID:uQr,项目名称:referencesource,代码行数:5,代码来源:x509certificate2.cs


示例20: GenerateSubjectKeyIdentifierFromPublicKey

        private static byte[] GenerateSubjectKeyIdentifierFromPublicKey(PublicKey key, X509SubjectKeyIdentifierHashAlgorithm algorithm)
        {
            switch (algorithm)
            {
                case X509SubjectKeyIdentifierHashAlgorithm.Sha1:
                    return ComputeSha1(key.EncodedKeyValue.RawData);

                case X509SubjectKeyIdentifierHashAlgorithm.ShortSha1:
                    {
                        byte[] sha1 = ComputeSha1(key.EncodedKeyValue.RawData);

                        //  ShortSha1: The keyIdentifier is composed of a four bit type field with
                        //  the value 0100 followed by the least significant 60 bits of the
                        //  SHA-1 hash of the value of the BIT STRING subjectPublicKey
                        // (excluding the tag, length, and number of unused bit string bits)
                        byte[] shortSha1 = new byte[8];
                        Buffer.BlockCopy(sha1, sha1.Length - 8, shortSha1, 0, shortSha1.Length);
                        shortSha1[0] &= 0x0f;
                        shortSha1[0] |= 0x40;
                        return shortSha1;
                    }

                case X509SubjectKeyIdentifierHashAlgorithm.CapiSha1:
                    return X509Pal.Instance.ComputeCapiSha1OfPublicKey(key);

                default:
                    throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, algorithm), nameof(algorithm));
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:29,代码来源:X509SubjectKeyIdentifierExtension.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# X509Certificates.X500DistinguishedName类代码示例发布时间:2022-05-26
下一篇:
C# Pkcs.SignedCms类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap