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


C# Crypto.AsymmetricCipherKeyPair类代码示例

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


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

示例1: GetPrivateKey

 /// <summary>
 /// Gets the PEM for the Private Key from the Asymmetric Key Pair.
 /// </summary>
 /// <param name="keys"></param>
 /// <returns></returns>
 public static String GetPrivateKey(AsymmetricCipherKeyPair keys)
 {
     TextWriter textWriter = new StringWriter();
     PemWriter pemWriter = new PemWriter(textWriter);
     pemWriter.WriteObject(keys.Private);
     pemWriter.Writer.Flush();
     return textWriter.ToString();
 }
开发者ID:TheCreatorJames,项目名称:BasylAKG,代码行数:13,代码来源:BasylRSAUtilities.cs

示例2: encodeUserKeyPairPrivate

        public static byte[] encodeUserKeyPairPrivate(AsymmetricCipherKeyPair userKey)
        {
            PrivateKeyInfo privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(userKey.Private);
            byte[] serializedPrivateBytes = privateKeyInfo.ToAsn1Object().GetDerEncoded();

            return serializedPrivateBytes;
        }
开发者ID:crypto-ink,项目名称:CryptoInkLib,代码行数:7,代码来源:FileEncUserKeyGen.cs

示例3: SaveToFile

        public static void SaveToFile(
            X509Certificate newCert,
            AsymmetricCipherKeyPair kp,
            string FilePath,
            string CertAlias,
            string Password)
        {
            var newStore = new Pkcs12Store();

            var certEntry = new X509CertificateEntry(newCert);

            newStore.SetCertificateEntry(
                CertAlias,
                certEntry
                );

            newStore.SetKeyEntry(
                CertAlias,
                new AsymmetricKeyEntry(kp.Private),
                new[] { certEntry }
                );

            using (var certFile = File.Create(FilePath))
            {
                newStore.Save(
                    certFile,
                    Password.ToCharArray(),
                    new SecureRandom(new CryptoApiRandomGenerator())
                    );
            }
        }
开发者ID:Piirtaa,项目名称:Decoratid,代码行数:31,代码来源:CertificateGenerator.cs

示例4: MakeCertificate

		public static X509Certificate MakeCertificate(AsymmetricCipherKeyPair _subKP,
			string _subDN, AsymmetricCipherKeyPair _issKP, string _issDN, string algorithm, bool _ca)
		{
			AsymmetricKeyParameter _subPub = _subKP.Public;
			AsymmetricKeyParameter _issPriv = _issKP.Private;
			AsymmetricKeyParameter _issPub = _issKP.Public;

			X509V3CertificateGenerator _v3CertGen = new X509V3CertificateGenerator();

			_v3CertGen.Reset();
			_v3CertGen.SetSerialNumber(allocateSerialNumber());
			_v3CertGen.SetIssuerDN(new X509Name(_issDN));
			_v3CertGen.SetNotBefore(DateTime.UtcNow);
			_v3CertGen.SetNotAfter(DateTime.UtcNow.AddDays(100));
			_v3CertGen.SetSubjectDN(new X509Name(_subDN));
			_v3CertGen.SetPublicKey(_subPub);
			_v3CertGen.SetSignatureAlgorithm(algorithm);

			_v3CertGen.AddExtension(X509Extensions.SubjectKeyIdentifier, false,
				createSubjectKeyId(_subPub));

			_v3CertGen.AddExtension(X509Extensions.AuthorityKeyIdentifier, false,
				createAuthorityKeyId(_issPub));

			_v3CertGen.AddExtension(X509Extensions.BasicConstraints, false,
				new BasicConstraints(_ca));

			X509Certificate _cert = _v3CertGen.Generate(_issPriv);

			_cert.CheckValidity(DateTime.UtcNow);
			_cert.Verify(_issPub);

			return _cert;
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:34,代码来源:OCSPTestUtil.cs

示例5: GetObsoleteSharedSecret

 public static byte[] GetObsoleteSharedSecret(AsymmetricCipherKeyPair localKeyWithPrivate, byte[] remotePublicKeyDerEncoded)
 {
     var remotePublicKey = PublicKeyFactory.CreateKey(remotePublicKeyDerEncoded);
     var agreement = new ECDHBasicAgreement();
     agreement.Init(localKeyWithPrivate.Private);
     return agreement.CalculateAgreement(remotePublicKey).ToByteArray();
 }
开发者ID:RoPe93,项目名称:CBcrypt,代码行数:7,代码来源:CBCryptKey.cs

示例6: PgpKeyPair

		public PgpKeyPair(
            PublicKeyAlgorithmTag	algorithm,
            AsymmetricCipherKeyPair	keyPair,
            DateTime				time)
			: this(algorithm, keyPair.Public, keyPair.Private, time)
        {
        }
开发者ID:htlp,项目名称:itextsharp,代码行数:7,代码来源:PgpKeyPair.cs

示例7: encodeUserKeyPairPublic

        public static byte[] encodeUserKeyPairPublic(AsymmetricCipherKeyPair userKey)
        {
            SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(userKey.Public);
            byte[] serializedPublicBytes = publicKeyInfo.ToAsn1Object().GetDerEncoded();

            return serializedPublicBytes;
        }
开发者ID:crypto-ink,项目名称:CryptoInkLib,代码行数:7,代码来源:FileEncUserKeyGen.cs

示例8: GenerateSigningRequestViaOpenSSL

		private void GenerateSigningRequestViaOpenSSL(string TargetCertRequestFileName, AsymmetricCipherKeyPair KeyPair)
		{
			// We expect openssl.exe to exist in the same directory as iPhonePackager
			string OpenSSLPath = Path.GetDirectoryName( Application.ExecutablePath ) + @"\openssl.exe";
			if (!File.Exists( OpenSSLPath ))
			{
				MessageBox.Show("A version of OpenSSL is required to generate certificate requests.  Please place OpenSSL.exe in Binaries\\DotNET\\IOS", Config.AppDisplayName, MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}

			string EffectiveBuildPath = (Program.GameName.Length > 0) ? Config.BuildDirectory : Path.GetFullPath(".");

			// Create a temporary file to write the key pair out to (in a format that OpenSSL understands)
			string KeyFileName = Path.GetTempFileName();
			TextWriter KeyWriter = new StreamWriter(KeyFileName);

			PemWriter KeyWriterPEM = new PemWriter(KeyWriter);
			KeyWriterPEM.WriteObject(KeyPair);
			KeyWriter.Close();

			// Create a temporary file containing the configuration settings to drive OpenSSL
			string ConfigFileName = Path.GetTempFileName();
			TextWriter ConfigFile = new StreamWriter(ConfigFileName);
				
			ConfigFile.WriteLine("[ req ]");
			ConfigFile.WriteLine("distinguished_name     = req_distinguished_name");
			ConfigFile.WriteLine("prompt                 = no");

			ConfigFile.WriteLine("[ req_distinguished_name ]");
			ConfigFile.WriteLine("emailAddress           = {0}", EMailEditBox.Text);
			ConfigFile.WriteLine("commonName             = {0}", CommonNameEditBox.Text);
			ConfigFile.WriteLine("countryName            = {0}", System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);

			ConfigFile.Close();

			// Invoke OpenSSL to generate the certificate request
			Program.Log("Running OpenSSL to generate certificate request...");

			string ResultsText;
			string Executable = OpenSSLPath;
			string Arguments = String.Format("req -new -nodes -out \"{0}\" -key \"{1}\" -config \"{2}\"",
				TargetCertRequestFileName, KeyFileName, ConfigFileName);
			Utilities.RunExecutableAndWait(Executable, Arguments, out ResultsText);

			Program.Log(ResultsText);

			if (!File.Exists(TargetCertRequestFileName))
			{
				Program.Error("... Failed to generate certificate request");
			}
			else
			{
				Program.Log("... Successfully generated certificate request '{0}'", TargetCertRequestFileName);
			}

			// Clean up the temporary files we created
			File.Delete(KeyFileName);
			File.Delete(ConfigFileName);
		}
开发者ID:xiangyuan,项目名称:Unreal4,代码行数:59,代码来源:GenerateSigningRequestDialog.cs

示例9: PkcsCertificate

 /// <summary>
 /// Public constructor for a Pkcs certificate, takes in values to describe it's state.
 /// </summary>
 /// <param name="password">The value used to secure (encrypt) the private key with the certificate</param>
 /// <param name="keypair">An object used for manipulating/accessing the public and private key of a certificate</param>
 /// <param name="cert">An easy to manipulate version of an X509 certificate</param>
 /// <param name="store">A store of Pkcs12 certificates used to store and manipulate certificat chains and key associations</param>
 public PkcsCertificate(string password ,AsymmetricCipherKeyPair keypair, Org.BouncyCastle.X509.X509Certificate cert, Pkcs12Store store)
 {
     this.Password = password;
     this.Keypair = keypair;
     this.X509Certificate = cert;
     this.PkcsStore = store;
     // this is not the best place to do this
 }
开发者ID:hughshanahan,项目名称:GWydiR,代码行数:15,代码来源:PkcsCertificate.cs

示例10: DkimTests

		static DkimTests ()
		{
			using (var stream = new StreamReader (Path.Combine ("..", "..", "TestData", "dkim", "example.pem"))) {
				var reader = new PemReader (stream);

				DkimKeys = reader.ReadObject () as AsymmetricCipherKeyPair;
			}
		}
开发者ID:dcga,项目名称:MimeKit,代码行数:8,代码来源:DkimTests.cs

示例11: ExportCertificate

 private static byte[] ExportCertificate(X509Certificate certificate, AsymmetricCipherKeyPair subjectKeyPair, TCertificateFormat certificateFormat)
 {
     byte[] result = null;
     switch (certificateFormat)
     {
         case TCertificateFormat.NotSet:
             break;
         case TCertificateFormat.PEM:
             using (MemoryStream stream = new MemoryStream())
             {
                 using (StreamWriter writer = new StreamWriter(stream))
                 {
                     Org.BouncyCastle.Utilities.IO.Pem.PemWriter pemWriter = new Org.BouncyCastle.Utilities.IO.Pem.PemWriter(writer);
                     if (subjectKeyPair.Private is ECKeyParameters)
                     {
                         ECPrivateKeyParameters priv = (ECPrivateKeyParameters)subjectKeyPair.Private;
                         ECDomainParameters dp = priv.Parameters;
                         int orderBitLength = dp.N.BitLength;
                         Org.BouncyCastle.Asn1.Sec.ECPrivateKeyStructure ec;
                         Org.BouncyCastle.Asn1.X9.X962Parameters x962;
                         if (priv.PublicKeyParamSet == null)
                         {
                             Org.BouncyCastle.Asn1.X9.X9ECParameters ecP = new Org.BouncyCastle.Asn1.X9.X9ECParameters(dp.Curve, dp.G, dp.N, dp.H, dp.GetSeed());
                             x962 = new Org.BouncyCastle.Asn1.X9.X962Parameters(ecP);
                         }
                         else
                         {
                             x962 = new Org.BouncyCastle.Asn1.X9.X962Parameters(priv.PublicKeyParamSet);
                         }
                         ec = new Org.BouncyCastle.Asn1.Sec.ECPrivateKeyStructure(orderBitLength, priv.D, SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(subjectKeyPair.Public).PublicKeyData, x962);
                         pemWriter.WriteObject(new Org.BouncyCastle.Utilities.IO.Pem.PemObject("EC PRIVATE KEY", ec.GetEncoded()));
                     }
                     else
                     {
                         pemWriter.WriteObject(new Org.BouncyCastle.OpenSsl.MiscPemGenerator(subjectKeyPair.Private));
                     }
                     pemWriter.WriteObject(new Org.BouncyCastle.OpenSsl.MiscPemGenerator(subjectKeyPair.Public));
                     pemWriter.WriteObject(new Org.BouncyCastle.OpenSsl.MiscPemGenerator(certificate));
                     writer.Flush();
                     result = stream.ToArray();
                 }
             }
             break;
         case TCertificateFormat.PFX:
             //Asn1Sequence asn1Sequence = Asn1Sequence.GetInstance(Asn1Object.FromByteArray(certificate.GetEncoded()));
             //asn1Sequence.GetObjects
             //Org.BouncyCastle.Asn1.Pkcs.Pfx pfx = new Org.BouncyCastle.Asn1.Pkcs.Pfx();
             //Org.BouncyCastle.Asn1.Pkcs.PrivateKeyInfo info = Org.BouncyCastle.Pkcs.PrivateKeyInfoFactory.CreatePrivateKeyInfo(subjectKeyPair.Private);
             //result = pfx.GetEncoded(Asn1Encodable.Der);
             break;
         case TCertificateFormat.CER:
             result = certificate.GetEncoded();
             break;
         default:
             break;
     }
     return result;
 }
开发者ID:CreatorDev,项目名称:DTLS.Net,代码行数:58,代码来源:Certificates.cs

示例12: GetPrivateKey

 // This returns a
 public static string GetPrivateKey(AsymmetricCipherKeyPair keyPair)
 {
     var dhPrivateKeyParameters = keyPair.Private as DHPrivateKeyParameters;
     if (dhPrivateKeyParameters != null)
     {
         return dhPrivateKeyParameters.X.ToString();
     }
     throw new NullReferenceException("The key pair provided is not a valid DH keypair.");
 }
开发者ID:WakeCaine,项目名称:AuthProject,代码行数:10,代码来源:MainWindow.xaml.cs

示例13: DHProvider

        public DHProvider(DHParameters parameters)
        {
            _parameters = parameters;

            IAsymmetricCipherKeyPairGenerator keyGen = GeneratorUtilities.GetKeyPairGenerator("DH");
            KeyGenerationParameters kgp = new DHKeyGenerationParameters(new SecureRandom(), _parameters);

            keyGen.Init(kgp);
            _kp = keyGen.GenerateKeyPair();
        }
开发者ID:soshimozi,项目名称:SocketServer,代码行数:10,代码来源:DHProvider.cs

示例14: GetSharedSecret

 public static byte[] GetSharedSecret(AsymmetricCipherKeyPair localKeyWithPrivate, byte[] remotePublicKeyDerEncoded)
 {
     var remotePublicKey = PublicKeyFactory.CreateKey(remotePublicKeyDerEncoded);
     var agreement = new ECDHBasicAgreement();
     agreement.Init(localKeyWithPrivate.Private);
     using (var sha = SHA256.Create()) {
         // CalculateAgreement returns a BigInteger, whose length is variable, and bits are not whitened.
         // So hash it.
         return sha.ComputeHash(agreement.CalculateAgreement(remotePublicKey).ToByteArray());
     }
 }
开发者ID:RoPe93,项目名称:CBcrypt,代码行数:11,代码来源:CBCryptKey.cs

示例15: ServerAuthority

        public ServerAuthority(DHParameters parameters)
        {
            this.parameters = parameters;

            IAsymmetricCipherKeyPairGenerator keyGen = GeneratorUtilities.GetKeyPairGenerator("DH");
            KeyGenerationParameters kgp = new DHKeyGenerationParameters(new SecureRandom(), parameters);

            keyGen.Init(kgp);
            kp = keyGen.GenerateKeyPair();
            agreement = AgreementUtilities.GetBasicAgreement("DH");
            agreement.Init(kp.Private);
        }
开发者ID:soshimozi,项目名称:SocketServer,代码行数:12,代码来源:ServerAuthority.cs


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