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


C# X509.SubjectPublicKeyInfo类代码示例

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


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

示例1: PopoSigningKeyInput

 /** Creates a new PopoSigningKeyInput using password-based MAC. */
 public PopoSigningKeyInput(
     PKMacValue pkmac,
     SubjectPublicKeyInfo spki)
 {
     this.publicKeyMac = pkmac;
     this.publicKey = spki;
 }
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:8,代码来源:PopoSigningKeyInput.cs

示例2: DecodePublicKey

        private static readonly AlgorithmIdentifier PublicKeyAlgorithm = AlgorithmIdentifier.GetInstance("1.2.840.113549.1.1.1"); // OID for RSA

        #endregion Fields

        #region Methods

        /// <summary>
        /// The decode public key.
        /// </summary>
        /// <param name="keyString">
        /// The key string.
        /// </param>
        /// <returns>
        /// The <see cref="PublicKey"/>.
        /// </returns>
        public PublicKey DecodePublicKey(string keyString)
        {
            byte[] data = Convert.FromBase64String(keyString);
            var keyInfo = new SubjectPublicKeyInfo(PublicKeyAlgorithm, data);
            AsymmetricKeyParameter publicKeyParam = PublicKeyFactory.CreateKey(keyInfo);
            return new PublicKey(publicKeyParam);
        }
开发者ID:hakandilek,项目名称:keysmith,代码行数:22,代码来源:KeyMaster.cs

示例3: PublicKeyAndChallenge

		public PublicKeyAndChallenge(
			Asn1Sequence seq)
		{
			pkacSeq = seq;
			spki = SubjectPublicKeyInfo.GetInstance(seq[0]);
			challenge = DerIA5String.GetInstance(seq[1]);
		}
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:7,代码来源:PublicKeyAndChallenge.cs

示例4: GetContentStream

		/**
		* decrypt the content and return an input stream.
		*/
		public override CmsTypedStream GetContentStream(
//			Key key)
			ICipherParameters key)
		{
			if (!(key is AsymmetricKeyParameter))
				throw new ArgumentException("KeyAgreement requires asymmetric key", "key");

			AsymmetricKeyParameter privKey = (AsymmetricKeyParameter) key;

			if (!privKey.IsPrivate)
				throw new ArgumentException("Expected private key", "key");

			try
			{
				OriginatorPublicKey origK = _info.Originator.OriginatorKey;
				PrivateKeyInfo privInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(privKey);
				SubjectPublicKeyInfo pubInfo = new SubjectPublicKeyInfo(privInfo.AlgorithmID, origK.PublicKey.GetBytes());
				AsymmetricKeyParameter pubKey = PublicKeyFactory.CreateKey(pubInfo);

				string wrapAlg = DerObjectIdentifier.GetInstance(
					Asn1Sequence.GetInstance(_keyEncAlg.Parameters)[0]).Id;

				IBasicAgreement agreement = AgreementUtilities.GetBasicAgreementWithKdf(
					_keyEncAlg.ObjectID, wrapAlg);

				agreement.Init(privKey);

				BigInteger wKeyNum = agreement.CalculateAgreement(pubKey);
				// TODO Fix the way bytes are derived from the secret
				byte[] wKeyBytes = wKeyNum.ToByteArrayUnsigned();
				KeyParameter wKey = ParameterUtilities.CreateKeyParameter(wrapAlg, wKeyBytes);

				IWrapper keyCipher = WrapperUtilities.GetWrapper(wrapAlg);

				keyCipher.Init(false, wKey);

				AlgorithmIdentifier aid = _encAlg;
				string alg = aid.ObjectID.Id;

				byte[] encryptedKey = _encryptedKey.GetOctets();
				byte[] sKeyBytes = keyCipher.Unwrap(encryptedKey, 0, encryptedKey.Length);

				KeyParameter sKey = ParameterUtilities.CreateKeyParameter(alg, sKeyBytes);

				return GetContentFromSessionKey(sKey);
			}
			catch (SecurityUtilityException e)
			{
				throw new CmsException("couldn't create cipher.", e);
			}
			catch (InvalidKeyException e)
			{
				throw new CmsException("key invalid in message.", e);
			}
			catch (Exception e)
			{
				throw new CmsException("originator key invalid.", e);
			}
		}
开发者ID:pusp,项目名称:o2platform,代码行数:62,代码来源:KeyAgreeRecipientInformation.cs

示例5: TbsCertificateStructure

        internal TbsCertificateStructure(
			Asn1Sequence seq)
        {
            int seqStart = 0;

            this.seq = seq;

            //
            // some certficates don't include a version number - we assume v1
            //
            if (seq[0] is DerTaggedObject)
            {
                version = DerInteger.GetInstance((Asn1TaggedObject)seq[0], true);
            }
            else
            {
                seqStart = -1;          // field 0 is missing!
                version = new DerInteger(0);
            }

            serialNumber = DerInteger.GetInstance(seq[seqStart + 1]);

            signature = AlgorithmIdentifier.GetInstance(seq[seqStart + 2]);
            issuer = X509Name.GetInstance(seq[seqStart + 3]);

            //
            // before and after dates
            //
            Asn1Sequence  dates = (Asn1Sequence)seq[seqStart + 4];

            startDate = Time.GetInstance(dates[0]);
            endDate = Time.GetInstance(dates[1]);

            subject = X509Name.GetInstance(seq[seqStart + 5]);

            //
            // public key info.
            //
            subjectPublicKeyInfo = SubjectPublicKeyInfo.GetInstance(seq[seqStart + 6]);

            for (int extras = seq.Count - (seqStart + 6) - 1; extras > 0; extras--)
            {
                DerTaggedObject extra = (DerTaggedObject) seq[seqStart + 6 + extras];

                switch (extra.TagNo)
                {
                    case 1:
                        issuerUniqueID = DerBitString.GetInstance(extra, false);
                        break;
                    case 2:
                        subjectUniqueID = DerBitString.GetInstance(extra, false);
                        break;
                    case 3:
                        extensions = X509Extensions.GetInstance(extra);
                        break;
                }
            }
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:58,代码来源:TBSCertificateStructure.cs

示例6: AuthorityKeyIdentifier

        /**
         *
         * Calulates the keyidentifier using a SHA1 hash over the BIT STRING
         * from SubjectPublicKeyInfo as defined in RFC2459.
         *
         * Example of making a AuthorityKeyIdentifier:
         * <pre>
         *   SubjectPublicKeyInfo apki = new SubjectPublicKeyInfo((ASN1Sequence)new ASN1InputStream(
         *       publicKey.getEncoded()).readObject());
         *   AuthorityKeyIdentifier aki = new AuthorityKeyIdentifier(apki);
         * </pre>
         *
         **/
        public AuthorityKeyIdentifier(
            SubjectPublicKeyInfo spki)
        {
            IDigest digest = new Sha1Digest();
            byte[] resBuf = new byte[digest.GetDigestSize()];

            byte[] bytes = spki.PublicKeyData.GetBytes();
            digest.BlockUpdate(bytes, 0, bytes.Length);
            digest.DoFinal(resBuf, 0);
            this.keyidentifier = new DerOctetString(resBuf);
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:24,代码来源:AuthorityKeyIdentifier.cs

示例7: SubjectKeyIdentifier

		/**
         *
         * Calulates the keyIdentifier using a SHA1 hash over the BIT STRING
         * from SubjectPublicKeyInfo as defined in RFC2459.
         *
         **/
        public SubjectKeyIdentifier(
            SubjectPublicKeyInfo spki)
        {
            IDigest digest = new Sha1Digest();
            byte[] resBuf = new byte[digest.GetDigestSize()];

			byte[] bytes = spki.PublicKeyData.GetBytes();
            digest.BlockUpdate(bytes, 0, bytes.Length);
            digest.DoFinal(resBuf, 0);
            this.keyIdentifier = resBuf;
        }
开发者ID:pusp,项目名称:o2platform,代码行数:17,代码来源:SubjectKeyIdentifier.cs

示例8: CertificationRequestInfo

		public CertificationRequestInfo(
            X509Name				subject,
            SubjectPublicKeyInfo	pkInfo,
            Asn1Set					attributes)
        {
            this.subject = subject;
            this.subjectPKInfo = pkInfo;
            this.attributes = attributes;

			if (subject == null || version == null || subjectPKInfo == null)
            {
                throw new ArgumentException(
					"Not all mandatory fields set in CertificationRequestInfo generator.");
            }
        }
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:15,代码来源:CertificationRequestInfo.cs

示例9: CertTemplate

        private CertTemplate(Asn1Sequence seq)
        {
            this.seq = seq;

            foreach (Asn1TaggedObject tObj in seq)
            {
                switch (tObj.TagNo)
                {
                case 0:
                    version = DerInteger.GetInstance(tObj, false);
                    break;
                case 1:
                    serialNumber = DerInteger.GetInstance(tObj, false);
                    break;
                case 2:
                    signingAlg = AlgorithmIdentifier.GetInstance(tObj, false);
                    break;
                case 3:
                    issuer = X509Name.GetInstance(tObj, true); // CHOICE
                    break;
                case 4:
                    validity = OptionalValidity.GetInstance(Asn1Sequence.GetInstance(tObj, false));
                    break;
                case 5:
                    subject = X509Name.GetInstance(tObj, true); // CHOICE
                    break;
                case 6:
                    publicKey = SubjectPublicKeyInfo.GetInstance(tObj, false);
                    break;
                case 7:
                    issuerUID = DerBitString.GetInstance(tObj, false);
                    break;
                case 8:
                    subjectUID = DerBitString.GetInstance(tObj, false);
                    break;
                case 9:
                    extensions = X509Extensions.GetInstance(tObj, false);
                    break;
                default:
                    throw new ArgumentException("unknown tag: " + tObj.TagNo, "seq");
                }
            }
        }
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:43,代码来源:CertTemplate.cs

示例10: TbsV1CertGenerate

        private void TbsV1CertGenerate()
        {
			V1TbsCertificateGenerator gen = new V1TbsCertificateGenerator();
            DateTime startDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 1);
            DateTime endDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 12);

            gen.SetSerialNumber(new DerInteger(1));

            gen.SetStartDate(new Time(startDate));
            gen.SetEndDate(new Time(endDate));

            gen.SetIssuer(new X509Name("CN=AU,O=Bouncy Castle"));
            gen.SetSubject(new X509Name("CN=AU,O=Bouncy Castle,OU=Test 1"));

            gen.SetSignature(new AlgorithmIdentifier(PkcsObjectIdentifiers.MD5WithRsaEncryption, DerNull.Instance));

            SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(PkcsObjectIdentifiers.RsaEncryption, DerNull.Instance),
                new RsaPublicKeyStructure(BigInteger.One, BigInteger.Two));

            gen.SetSubjectPublicKeyInfo(info);

            TbsCertificateStructure tbs = gen.GenerateTbsCertificate();

			if (!Arrays.AreEqual(tbs.GetEncoded(), v1Cert))
            {
                Fail("failed v1 cert generation");
            }

            //
            // read back test
            //
            Asn1InputStream aIn = new Asn1InputStream(v1Cert);
            Asn1Object o = aIn.ReadObject();

            if (!Arrays.AreEqual(o.GetEncoded(), v1Cert))
            {
                Fail("failed v1 cert read back test");
            }
        }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:39,代码来源:GenerationTest.cs

示例11: CreateTruncatedSha1KeyIdentifier

		/**
		 * Return a RFC 3280 type 2 key identifier. As in:
		 * <pre>
		 * (2) 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.
		 * </pre>
		 * @param keyInfo the key info object containing the subjectPublicKey field.
		 * @return the key identifier.
		 */
		public static SubjectKeyIdentifier CreateTruncatedSha1KeyIdentifier(
			SubjectPublicKeyInfo keyInfo)
		{
			byte[] dig = GetDigest(keyInfo);
			byte[] id = new byte[8];

			Array.Copy(dig, dig.Length - 8, id, 0, id.Length);

			id[0] &= 0x0f;
			id[0] |= 0x40;

			return new SubjectKeyIdentifier(id);
		}
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:23,代码来源:SubjectKeyIdentifier.cs

示例12: CreateSubjectPublicKeyInfo

		/// <summary>
        /// Create a Subject Public Key Info object for a given public key.
        /// </summary>
        /// <param name="key">One of ElGammalPublicKeyParameters, DSAPublicKeyParameter, DHPublicKeyParameters, RsaKeyParameters or ECPublicKeyParameters</param>
        /// <returns>A subject public key info object.</returns>
        /// <exception cref="Exception">Throw exception if object provided is not one of the above.</exception>
        public static SubjectPublicKeyInfo CreateSubjectPublicKeyInfo(
			AsymmetricKeyParameter key)
        {
			if (key == null)
				throw new ArgumentNullException("key");
            if (key.IsPrivate)
                throw new ArgumentException("Private key passed - public key expected.", "key");

			if (key is ElGamalPublicKeyParameters)
            {
				ElGamalPublicKeyParameters _key = (ElGamalPublicKeyParameters)key;
				ElGamalParameters kp = _key.Parameters;

				SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
					new AlgorithmIdentifier(
						OiwObjectIdentifiers.ElGamalAlgorithm,
						new ElGamalParameter(kp.P, kp.G).ToAsn1Object()),
						new DerInteger(_key.Y));

				return info;
            }

			if (key is DsaPublicKeyParameters)
            {
                DsaPublicKeyParameters _key = (DsaPublicKeyParameters) key;
				DsaParameters kp = _key.Parameters;
				Asn1Encodable ae = kp == null
					?	null
					:	new DsaParameter(kp.P, kp.Q, kp.G).ToAsn1Object();

				return new SubjectPublicKeyInfo(
                    new AlgorithmIdentifier(X9ObjectIdentifiers.IdDsa, ae),
					new DerInteger(_key.Y));
            }

			if (key is DHPublicKeyParameters)
            {
                DHPublicKeyParameters _key = (DHPublicKeyParameters) key;
				DHParameters kp = _key.Parameters;

				SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
                    new AlgorithmIdentifier(
						X9ObjectIdentifiers.DHPublicNumber,
						new DHParameter(kp.P, kp.G, kp.L).ToAsn1Object()),
						new DerInteger(_key.Y));

				return info;
            } // End of DH

            if (key is RsaKeyParameters)
            {
                RsaKeyParameters _key = (RsaKeyParameters) key;

				SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
					new AlgorithmIdentifier(PkcsObjectIdentifiers.RsaEncryption, DerNull.Instance),
					new RsaPublicKeyStructure(_key.Modulus, _key.Exponent).ToAsn1Object());

				return info;
            } // End of RSA.

			if (key is ECPublicKeyParameters)
            {
                ECPublicKeyParameters _key = (ECPublicKeyParameters) key;

				if (_key.AlgorithmName == "ECGOST3410")
				{
					if (_key.PublicKeyParamSet == null)
						throw Platform.CreateNotImplementedException("Not a CryptoPro parameter set");

					ECPoint q = _key.Q;
					BigInteger bX = q.X.ToBigInteger();
					BigInteger bY = q.Y.ToBigInteger();

					byte[] encKey = new byte[64];
					ExtractBytes(encKey, 0, bX);
					ExtractBytes(encKey, 32, bY);

					Gost3410PublicKeyAlgParameters gostParams = new Gost3410PublicKeyAlgParameters(
						_key.PublicKeyParamSet, CryptoProObjectIdentifiers.GostR3411x94CryptoProParamSet);

					AlgorithmIdentifier algID = new AlgorithmIdentifier(
						CryptoProObjectIdentifiers.GostR3410x2001,
						gostParams.ToAsn1Object());

					return new SubjectPublicKeyInfo(algID, new DerOctetString(encKey));
				}
				else
				{
					ECDomainParameters kp = _key.Parameters;

					X9ECParameters ecP = new X9ECParameters(kp.Curve, kp.G, kp.N, kp.H, kp.GetSeed());
					X962Parameters x962 = new X962Parameters(ecP);
					Asn1OctetString p = (Asn1OctetString)(new X9ECPoint(_key.Q).ToAsn1Object());

//.........这里部分代码省略.........
开发者ID:nicecai,项目名称:iTextSharp-4.1.6,代码行数:101,代码来源:SubjectPublicKeyInfoFactory.cs

示例13: GetPublicKeyFromOriginatorPublicKey

 private AsymmetricKeyParameter GetPublicKeyFromOriginatorPublicKey(
     AsymmetricKeyParameter	receiverPrivateKey,
     OriginatorPublicKey		originatorPublicKey)
 {
     PrivateKeyInfo privInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(receiverPrivateKey);
     SubjectPublicKeyInfo pubInfo = new SubjectPublicKeyInfo(
         privInfo.PrivateKeyAlgorithm,
         originatorPublicKey.PublicKey.GetBytes());
     return PublicKeyFactory.CreateKey(pubInfo);
 }
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:10,代码来源:KeyAgreeRecipientInformation.cs

示例14: SetSubjectPublicKeyInfo

		public void SetSubjectPublicKeyInfo(
            SubjectPublicKeyInfo pubKeyInfo)
        {
            this.subjectPublicKeyInfo = pubKeyInfo;
        }
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:5,代码来源:V1TBSCertificateGenerator.cs

示例15: CreateKey

		public static AsymmetricKeyParameter CreateKey(
			SubjectPublicKeyInfo keyInfo)
        {
            AlgorithmIdentifier algID = keyInfo.AlgorithmID;
			DerObjectIdentifier algOid = algID.ObjectID;

			// TODO See RSAUtil.isRsaOid in Java build
			if (algOid.Equals(PkcsObjectIdentifiers.RsaEncryption)
				|| algOid.Equals(X509ObjectIdentifiers.IdEARsa)
				|| algOid.Equals(PkcsObjectIdentifiers.IdRsassaPss)
				|| algOid.Equals(PkcsObjectIdentifiers.IdRsaesOaep))
			{
				RsaPublicKeyStructure pubKey = RsaPublicKeyStructure.GetInstance(
					keyInfo.GetPublicKey());

				return new RsaKeyParameters(false, pubKey.Modulus, pubKey.PublicExponent);
			}
			else if (algOid.Equals(PkcsObjectIdentifiers.DhKeyAgreement)
				|| algOid.Equals(X9ObjectIdentifiers.DHPublicNumber))
			{
				DHParameter para = new DHParameter(
					Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object()));
				DerInteger derY = (DerInteger) keyInfo.GetPublicKey();

				BigInteger lVal = para.L;
				int l = lVal == null ? 0 : lVal.IntValue;
				DHParameters dhParams = new DHParameters(para.P, para.G, null, l);

				return new DHPublicKeyParameters(derY.Value, dhParams);
			}
			else if (algOid.Equals(OiwObjectIdentifiers.ElGamalAlgorithm))
			{
				ElGamalParameter para = new ElGamalParameter(
					Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object()));
				DerInteger derY = (DerInteger) keyInfo.GetPublicKey();

				return new ElGamalPublicKeyParameters(
					derY.Value,
					new ElGamalParameters(para.P, para.G));
			}
			else if (algOid.Equals(X9ObjectIdentifiers.IdDsa)
				|| algOid.Equals(OiwObjectIdentifiers.DsaWithSha1))
			{
				DerInteger derY = (DerInteger) keyInfo.GetPublicKey();
				Asn1Encodable ae = algID.Parameters;

				DsaParameters parameters = null;
				if (ae != null)
				{
					DsaParameter para = DsaParameter.GetInstance(ae.ToAsn1Object());
					parameters = new DsaParameters(para.P, para.Q, para.G);
				}

				return new DsaPublicKeyParameters(derY.Value, parameters);
			}
			else if (algOid.Equals(X9ObjectIdentifiers.IdECPublicKey))
			{
				X962Parameters para = new X962Parameters(
					algID.Parameters.ToAsn1Object());
				X9ECParameters ecP;

				if (para.IsNamedCurve)
				{
					// TODO ECGost3410NamedCurves support (returns ECDomainParameters though)

					DerObjectIdentifier oid = (DerObjectIdentifier)para.Parameters;
					ecP = X962NamedCurves.GetByOid(oid);

					if (ecP == null)
					{
						ecP = SecNamedCurves.GetByOid(oid);

						if (ecP == null)
						{
							ecP = NistNamedCurves.GetByOid(oid);

							if (ecP == null)
							{
								ecP = TeleTrusTNamedCurves.GetByOid(oid);
							}
						}
					}
				}
				else
				{
					ecP = new X9ECParameters((Asn1Sequence)para.Parameters);
				}

				ECDomainParameters dParams = new ECDomainParameters(
					ecP.Curve,
					ecP.G,
					ecP.N,
					ecP.H,
					ecP.GetSeed());

				DerBitString bits = keyInfo.PublicKeyData;
				byte[] data = bits.GetBytes();
				Asn1OctetString key = new DerOctetString(data);

				X9ECPoint derQ = new X9ECPoint(dParams.Curve, key);
//.........这里部分代码省略.........
开发者ID:nicecai,项目名称:iTextSharp-4.1.6,代码行数:101,代码来源:PublicKeyFactory.cs


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