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


C# Crypto.AsymmetricKeyParameter类代码示例

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


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

示例1: Create

        private X509Certificate Create(CertificateRequest request, AsymmetricKeyParameter key)
        {
            try
            {
                var certGen = new X509V3CertificateGenerator();

                certGen.SetSerialNumber(BigInteger.ProbablePrime(128, new SecureRandom()));

                certGen.SetIssuerDN(new X509Name(_issuer));

                certGen.SetNotBefore(request.NotBefore);
                certGen.SetNotAfter(request.NotAfter);

                certGen.SetSubjectDN(new X509Name(_subject));
                certGen.SetPublicKey(_subjectPublicKey.PublicAsymmetricKey);

                certGen.SetSignatureAlgorithm("SHA1WITHRSA");

                certGen.AddExtension(X509Extensions.BasicConstraints, false, new BasicConstraints(true));

                return certGen.Generate(key);
            }
            catch (Exception e)
            {
                throw new SecularException("Error generating certificate: " + e.Message, e);
            }
        }
开发者ID:bitdiff,项目名称:secular,代码行数:27,代码来源:Certificate.cs

示例2: Generate

        /// <summary>
        /// Generate a new X509Certificate specifying a SecureRandom instance that you would like to use.
        /// </summary>
        /// <param name="privateKey">The private key of the issuer used to sign this certificate.</param>
        /// <param name="random">The Secure Random you want to use.</param>
        /// <returns>An X509Certificate.</returns>
        public X509Certificate Generate(
            AsymmetricKeyParameter	privateKey,
            SecureRandom			random)
        {
            TbsCertificateStructure tbsCert = tbsGen.GenerateTbsCertificate();
            byte[] signature;

            try
            {
                signature = X509Utilities.GetSignatureForObject(
                    sigOID, signatureAlgorithm, privateKey, random, tbsCert);
            }
            catch (Exception e)
            {
                // TODO
            //				throw new ExtCertificateEncodingException("exception encoding TBS cert", e);
                throw new CertificateEncodingException("exception encoding TBS cert", e);
            }

            try
            {
                return GenerateJcaObject(tbsCert, signature);
            }
            catch (CertificateParsingException e)
            {
                // TODO
                // throw new ExtCertificateEncodingException("exception producing certificate object", e);
                throw new CertificateEncodingException("exception producing certificate object", e);
            }
        }
开发者ID:JamieMellway,项目名称:iTextSharpLGPL-Monotouch,代码行数:36,代码来源:X509V1CertificateGenerator.cs

示例3: CmsSigner

		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.Cryptography.CmsSigner"/> class.
		/// </summary>
		/// <remarks>
		/// <para>The initial value of the <see cref="DigestAlgorithm"/> will be set to
		/// <see cref="MimeKit.Cryptography.DigestAlgorithm.Sha1"/> and both the
		/// <see cref="SignedAttributes"/> and <see cref="UnsignedAttributes"/> properties
		/// will be initialized to empty tables.</para>
		/// </remarks>
		/// <param name="chain">The chain of certificates starting with the signer's certificate back to the root.</param>
		/// <param name="key">The signer's private key.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="chain"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="key"/> is <c>null</c>.</para>
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// <para><paramref name="chain"/> did not contain any certificates.</para>
		/// <para>-or-</para>
		/// <para>The certificate cannot be used for signing.</para>
		/// <para>-or-</para>
		/// <para><paramref name="key"/> is not a private key.</para>
		/// </exception>
		public CmsSigner (IEnumerable<X509CertificateEntry> chain, AsymmetricKeyParameter key) : this ()
		{
			if (chain == null)
				throw new ArgumentNullException ("chain");

			if (key == null)
				throw new ArgumentNullException ("key");

			CertificateChain = new X509CertificateChain ();
			foreach (var entry in chain) {
				CertificateChain.Add (entry.Certificate);
				if (Certificate == null)
					Certificate = entry.Certificate;
			}

			if (CertificateChain.Count == 0)
				throw new ArgumentException ("The certificate chain was empty.", "chain");

			var flags = Certificate.GetKeyUsageFlags ();
			if (flags != X509KeyUsageFlags.None && (flags & X509KeyUsageFlags.DigitalSignature) == 0)
				throw new ArgumentException ("The certificate cannot be used for signing.");

			if (!key.IsPrivate)
				throw new ArgumentException ("The key must be a private key.", "key");

			PrivateKey = key;
		}
开发者ID:gphummer,项目名称:MimeKit,代码行数:50,代码来源:CmsSigner.cs

示例4: AsymmetricKeyEntry

        public AsymmetricKeyEntry(
            AsymmetricKeyParameter  key,
            IDictionary             attributes)
			: base(attributes)
        {
            this.key = key;
        }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:7,代码来源:AsymmetricKeyEntry.cs

示例5: SignerInfoGeneratorImpl

			internal SignerInfoGeneratorImpl(
				CmsSignedDataStreamGenerator	outer,
				AsymmetricKeyParameter			key,
				SignerIdentifier				signerIdentifier,
				string							digestOID,
				string							encOID,
				CmsAttributeTableGenerator		sAttr,
				CmsAttributeTableGenerator		unsAttr)
			{
				this.outer = outer;

				_signerIdentifier = signerIdentifier;
				_digestOID = digestOID;
				_encOID = encOID;
				_sAttr = sAttr;
				_unsAttr = unsAttr;
				_encName = Helper.GetEncryptionAlgName(_encOID);

				string digestName = Helper.GetDigestAlgName(_digestOID);
				string signatureName = digestName + "with" + _encName;

				if (_sAttr != null)
				{
            		_sig = Helper.GetSignatureInstance(signatureName);
				}
				else
				{
					// Note: Need to use raw signatures here since we have already calculated the digest
					if (_encName.Equals("RSA"))
					{
						_sig = Helper.GetSignatureInstance("RSA");
					}
					else if (_encName.Equals("DSA"))
					{
						_sig = Helper.GetSignatureInstance("NONEwithDSA");
					}
					// TODO Add support for raw PSS
//					else if (_encName.equals("RSAandMGF1"))
//					{
//						_sig = CMSSignedHelper.INSTANCE.getSignatureInstance("NONEWITHRSAPSS", _sigProvider);
//						try
//						{
//							// Init the params this way to avoid having a 'raw' version of each PSS algorithm
//							Signature sig2 = CMSSignedHelper.INSTANCE.getSignatureInstance(signatureName, _sigProvider);
//							PSSParameterSpec spec = (PSSParameterSpec)sig2.getParameters().getParameterSpec(PSSParameterSpec.class);
//							_sig.setParameter(spec);
//						}
//						catch (Exception e)
//						{
//							throw new SignatureException("algorithm: " + _encName + " could not be configured.");
//						}
//					}
					else
					{
						throw new SignatureException("algorithm: " + _encName + " not supported in base signatures.");
					}
				}

				_sig.Init(true, new ParametersWithRandom(key, outer.rand));
			}
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:60,代码来源:CMSSignedDataStreamGenerator.cs

示例6: AddSigner

 /**
 * add a signer - no attributes other than the default ones will be
 * provided here.
 *
 * @param key signing key to use
 * @param cert certificate containing corresponding public key
 * @param digestOID digest algorithm OID
 */
 public void AddSigner(
     AsymmetricKeyParameter	privateKey,
     X509Certificate			cert,
     string					digestOID)
 {
     AddSigner(privateKey, cert, GetEncOid(privateKey, digestOID), digestOID);
 }
开发者ID:karino2,项目名称:wikipediaconv,代码行数:15,代码来源:CMSSignedDataGenerator.cs

示例7: GetConnectionHttpsPrivate

	    private Connection GetConnectionHttpsPrivate(Uri uri, Uri proxy, AsymmetricKeyParameter asymmetricKeyParameter,
	                                                 Certificate clientCertificates,
	                                                 Action<Certificate> serverCertificateValidator)
	    {
			Connection conn = new HttpsConnection(this, uri, proxy, clientCertificates, asymmetricKeyParameter, serverCertificateValidator);
		    return InitiateConnection(conn);
	    }
开发者ID:oblivious,项目名称:Oblivious,代码行数:7,代码来源:HttpConnectionFactory.cs

示例8: CreateCert

        public static Org.BouncyCastle.X509.X509Certificate CreateCert(String cn,
            AsymmetricKeyParameter pubKey, AsymmetricKeyParameter privKey)
        {
            Hashtable attrs = new Hashtable();
            attrs.Add(X509Name.CN, cn);

            ArrayList ord = new ArrayList(attrs.Keys);

            X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();

            certGen.SetSerialNumber(BigInteger.One);
            certGen.SetIssuerDN(new X509Name(ord, attrs));
            certGen.SetNotBefore(DateTime.UtcNow.AddDays(-30));
            certGen.SetNotAfter(DateTime.UtcNow.AddDays(30));
            certGen.SetSubjectDN(new X509Name(ord, attrs));
            certGen.SetPublicKey(pubKey);
            certGen.SetSignatureAlgorithm("SHA1WithRSAEncryption");

            Org.BouncyCastle.X509.X509Certificate cert = certGen.Generate(privKey);

            cert.CheckValidity(DateTime.UtcNow);

            cert.Verify(pubKey);

            return cert;
        }
开发者ID:maugsan,项目名称:dcfd-mw-applet,代码行数:26,代码来源:KeyStoreUtil.cs

示例9: GetSenderPublicKey

        private AsymmetricKeyParameter GetSenderPublicKey(
            AsymmetricKeyParameter		receiverPrivateKey,
            OriginatorIdentifierOrKey	originator)
        {
            OriginatorPublicKey opk = originator.OriginatorPublicKey;
            if (opk != null)
            {
                return GetPublicKeyFromOriginatorPublicKey(receiverPrivateKey, opk);
            }
            
            OriginatorID origID = new OriginatorID();
            
            Asn1.Cms.IssuerAndSerialNumber iAndSN = originator.IssuerAndSerialNumber;
            if (iAndSN != null)
            {
                origID.Issuer = iAndSN.Name;
                origID.SerialNumber = iAndSN.SerialNumber.Value;
            }
            else
            {
                SubjectKeyIdentifier ski = originator.SubjectKeyIdentifier;

                origID.SubjectKeyIdentifier = ski.GetKeyIdentifier();
            }

            return GetPublicKeyFromOriginatorID(origID);
        }
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:27,代码来源:KeyAgreeRecipientInformation.cs

示例10: ComputeSharedSecret

 public static BigInteger ComputeSharedSecret(string A, AsymmetricKeyParameter bPrivateKey, DHParameters internalParameters)
 {
     var importedKey = new DHPublicKeyParameters(new BigInteger(A), internalParameters);
     var internalKeyAgree = AgreementUtilities.GetBasicAgreement("DH");
     internalKeyAgree.Init(bPrivateKey);
     return internalKeyAgree.CalculateAgreement(importedKey);
 }
开发者ID:WakeCaine,项目名称:AuthProject,代码行数:7,代码来源:MainWindow.xaml.cs

示例11: TimeStampTokenGenerator

        /**
         * create with a signer with extra signed/unsigned attributes.
         */
        public TimeStampTokenGenerator(
			AsymmetricKeyParameter	key,
			X509Certificate			cert,
			string					digestOID,
			string					tsaPolicyOID,
			Asn1.Cms.AttributeTable	signedAttr,
			Asn1.Cms.AttributeTable	unsignedAttr)
        {
            this.key = key;
            this.cert = cert;
            this.digestOID = digestOID;
            this.tsaPolicyOID = tsaPolicyOID;
            this.unsignedAttr = unsignedAttr;

            TspUtil.ValidateCertificate(cert);

            //
            // add the essCertid
            //
            Hashtable signedAttrs;
            if (signedAttr != null)
            {
                signedAttrs = signedAttr.ToHashtable();
            }
            else
            {
                signedAttrs = new Hashtable();
            }

            IDigest digest;
            try
            {
                digest = DigestUtilities.GetDigest("SHA-1");
            }
            catch (Exception e)
            {
                throw new TspException("Can't find a SHA-1 implementation.", e);
            }

            try
            {
                byte[] certEncoded = cert.GetEncoded();
                digest.BlockUpdate(certEncoded, 0, certEncoded.Length);
                byte[] hash = DigestUtilities.DoFinal(digest);

                EssCertID essCertid = new EssCertID(hash);

                Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(
                    PkcsObjectIdentifiers.IdAASigningCertificate,
                    new DerSet(new SigningCertificate(essCertid)));

                signedAttrs[attr.AttrType] = attr;
            }
            catch (CertificateEncodingException e)
            {
                throw new TspException("Exception processing certificate.", e);
            }

            this.signedAttr = new Asn1.Cms.AttributeTable(signedAttrs);
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:63,代码来源:TimeStampTokenGenerator.cs

示例12: Pkcs8Generator

		/**
		* Constructor for an encrypted private key PEM object.
		*
		* @param key       private key to be encoded
		* @param algorithm encryption algorithm to use
		* @param provider  provider to use
		* @throws NoSuchAlgorithmException if algorithm/mode cannot be found
		*/
		public Pkcs8Generator(AsymmetricKeyParameter privKey, string algorithm)
		{
			// TODO Check privKey.IsPrivate
			this.privKey = privKey;
			this.algorithm = algorithm;
			this.iterationCount = 2048;
		}
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:15,代码来源:Pkcs8Generator.cs

示例13: AsymmetricKeyEntry

 public AsymmetricKeyEntry(
     AsymmetricKeyParameter	key,
     Hashtable				attributes)
     : base(attributes)
 {
     this.key = key;
 }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:7,代码来源:AsymmetricKeyEntry.cs

示例14: Sign

 public void Sign(AsymmetricKeyParameter privateKey)
 {
     var signer = new ECDsaSigner();
     signer.Init(true, privateKey);
     var signature = signer.GenerateSignature(t.getBytes);
     r = signature[0].ToByteArray();
     s = signature[1].ToByteArray();
 }
开发者ID:renegat96,项目名称:thymeMockup,代码行数:8,代码来源:Transaction.cs

示例15: AddSigner

 /**
 * add a signer - no attributes other than the default ones will be
 * provided here.
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeyException
 */
 public void AddSigner(
     AsymmetricKeyParameter	privateKey,
     X509Certificate			cert,
     string					digestOID)
 {
     AddSigner(privateKey, cert, digestOID,
         new DefaultSignedAttributeTableGenerator(), null);
 }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:14,代码来源:CMSSignedDataStreamGenerator.cs


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