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


C# Core.BIO类代码示例

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


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

示例1: LoadPKCS12Certificate

		public static X509Certificate LoadPKCS12Certificate(string resource, string password)
		{
			using (var bio = new BIO(LoadBytes(resource)))
			{
				return X509Certificate.FromPKCS12(bio, password);
			}
		}
开发者ID:chang892886597,项目名称:openssl-net,代码行数:7,代码来源:Util.cs

示例2: PKCS12

		/// <summary>
		/// Calls d2i_PKCS12_bio() and then PKCS12_parse()
		/// </summary>
		/// <param name="bio"></param>
		/// <param name="password"></param>
		public PKCS12(BIO bio, string password)
			: base(Native.ExpectNonNull(Native.d2i_PKCS12_bio(bio.Handle, IntPtr.Zero)), true)
		{
			IntPtr cert;
			IntPtr pkey;
			IntPtr cacerts;

			// Parse the PKCS12 object and get privatekey, cert, cacerts if available
			Native.ExpectSuccess(Native.PKCS12_parse(this.ptr, password, out pkey, out cert, out cacerts));

			if (cert != IntPtr.Zero)
			{
				this.certificate = new X509Certificate(cert, true);
				if (pkey != IntPtr.Zero)
				{
					this.privateKey = new CryptoKey(pkey, true);

					// We have a private key, assign it to the cert
					this.certificate.PrivateKey = this.privateKey.CopyRef();
				}
			}
			if (cacerts != IntPtr.Zero)
			{
				this.caCertificates = new Core.Stack<X509Certificate>(cacerts, true);
			}
		}
开发者ID:kengmail,项目名称:OpenSSL.NET,代码行数:31,代码来源:PKCS12.cs

示例3: LoadX509Chain

		public static X509Chain LoadX509Chain(string resource)
		{
			using (var bio = new BIO(LoadBytes(resource)))
			{
				return new X509Chain(bio);
			}
		}
开发者ID:chang892886597,项目名称:openssl-net,代码行数:7,代码来源:Util.cs

示例4: CanLoadFromPKCS7_DER

		public void CanLoadFromPKCS7_DER()
		{
			using (BIO bio = new BIO(LoadBytes(Resources.CaChainP7c))) {
				using (X509Certificate cert = X509Certificate.FromPKCS7_DER(bio)) {
					TestCert(cert, "CN=Root", "CN=Root", 1234);
				}
			}
		}
开发者ID:challal,项目名称:scallion,代码行数:8,代码来源:TestX509Certificate.cs

示例5: CanLoadFromPKCS7_PEM

		public void CanLoadFromPKCS7_PEM()
		{
			using (BIO bio = new BIO(LoadString(Resources.CaChainP7cPem))) {
				using (X509Certificate cert = X509Certificate.FromPKCS7_PEM(bio)) {
					TestCert(cert, "CN=Root", "CN=Root", 1234);
				}
			}
		}
开发者ID:challal,项目名称:scallion,代码行数:8,代码来源:TestX509Certificate.cs

示例6: CanLoadFromPEM

		public void CanLoadFromPEM()
		{
			using (BIO bio = new BIO(LoadString(Resources.CaCrt))) {
				using (X509Certificate cert = new X509Certificate(bio)) {
					TestCert(cert, "CN=Root", "CN=Root", 1234);
				}
			}
		}
开发者ID:challal,项目名称:scallion,代码行数:8,代码来源:TestX509Certificate.cs

示例7: CanLoadFromDER

		public void CanLoadFromDER()
		{
			using (var bio = new BIO(Util.LoadBytes(Resources.CaDer)))
			{
				using (var cert = X509Certificate.FromDER(bio))
				{
					TestCert(cert, "CN=Root", "CN=Root", 1234);
				}
			}
		}
开发者ID:yaobos,项目名称:openssl-net,代码行数:10,代码来源:TestX509Certificate.cs

示例8: Print

		/// <summary>
		/// Prints the LongName of this cipher.
		/// </summary>
		/// <param name="bio"></param>
		public override void Print(BIO bio)
		{
			bio.Write(this.LongName);
		}
开发者ID:langhuihui,项目名称:csharprtmp,代码行数:8,代码来源:Cipher.cs

示例9: WritePrivateKey

		/// <summary>
		/// Calls PEM_write_bio_RSAPrivateKey()
		/// </summary>
		/// <param name="bio"></param>
		/// <param name="enc"></param>
		/// <param name="passwd"></param>
		/// <param name="arg"></param>
		public void WritePrivateKey(BIO bio, Cipher enc, PasswordHandler passwd, object arg)
		{
			PasswordThunk thunk = new PasswordThunk(passwd, arg);
			Native.ExpectSuccess(Native.PEM_write_bio_RSAPrivateKey(
				bio.Handle,
				this.ptr,
				enc == null ? IntPtr.Zero : enc.Handle,
				null,
				0,
				thunk.Callback,
				IntPtr.Zero));
		}
开发者ID:wow4all,项目名称:mooege,代码行数:19,代码来源:RSA.cs

示例10: FromPrivateKey

		/// <summary>
		/// Calls PEM_read_bio_RSAPrivateKey()
		/// </summary>
		/// <param name="bio"></param>
		/// <param name="callback"></param>
		/// <param name="arg"></param>
		/// <returns></returns>
		public static RSA FromPrivateKey(BIO bio, PasswordHandler callback, object arg)
		{
			PasswordThunk thunk = new PasswordThunk(callback, arg);
			IntPtr ptr = Native.PEM_read_bio_RSAPrivateKey(bio.Handle, IntPtr.Zero, thunk.Callback, IntPtr.Zero);
			return new RSA(Native.ExpectNonNull(ptr), true);
		}
开发者ID:wow4all,项目名称:mooege,代码行数:13,代码来源:RSA.cs

示例11: FromPrivateKey

		/// <summary>
		/// Returns PEM_read_bio_DSAPrivateKey()
		/// </summary>
		/// <param name="bio"></param>
		/// <returns></returns>
		public static DSA FromPrivateKey(BIO bio)
		{
			return new DSA(Native.ExpectNonNull(Native.PEM_read_bio_DSAPrivateKey(bio.Handle, IntPtr.Zero, null, IntPtr.Zero)), true);
		}
开发者ID:Nangal,项目名称:http2-katana,代码行数:9,代码来源:DSA.cs

示例12: DtlsAssociation

    /// <summary>Create a DtlsFilter.</summary>
    /// <param name="key">A CryptoKey initialized by the OpenSSL.NET library.</param>
    /// <param name="cert">The path to the certificate to use.</param>
    /// <param name="ca_cert">The path to the ca certificate to use.</param>
    /// <param name="client">Use client initialization parameters.</param>
    public DtlsAssociation(ISender sender, CertificateHandler ch, PType ptype,
        Ssl ssl, bool client) : base(sender, ch)
    {
      _ip = new IdentifierPair();
      PType = ptype;
      _ssl = ssl;
      _client = client;
      _ssl.SetReadAhead(1);
      // Buggy SSL versions have issue with compression and dtls
      _ssl.SetOptions((int) SslOptions.SSL_OP_NO_COMPRESSION);
      if(client) {
        _ssl.SetConnectState();
      } else {
        _ssl.SetAcceptState();
      }

      // The ssl object will take control
      _read = BIO.MemoryBuffer(false);
      _read.NonBlocking = true;
      _write = BIO.MemoryBuffer(false);
      _write.NonBlocking = true;

      _ssl.SetBIO(_read, _write);
      _ssl.DoHandshake();

      _buffer = new byte[Int16.MaxValue];
      _buffer_sync = new object();
      _fe_lock = 0;
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:34,代码来源:DtlsAssociation.cs

示例13: Verify

		/// <summary>
		/// Calls EVP_VerifyFinal()
		/// </summary>
		/// <param name="md"></param>
		/// <param name="bio"></param>
		/// <param name="sig"></param>
		/// <param name="pkey"></param>
		/// <returns></returns>
		public static bool Verify(MessageDigest md, BIO bio, byte[] sig, CryptoKey pkey)
		{
			BIO bmd = BIO.MessageDigest(md);
			bmd.Push(bio);

			while (true)
			{
				ArraySegment<byte> bytes = bmd.ReadBytes(1024 * 4);
				if (bytes.Count == 0)
					break;
			}

			MessageDigestContext ctx = new MessageDigestContext(bmd);

			int ret = Native.ExpectSuccess(Native.EVP_VerifyFinal(ctx.Handle, sig, (uint)sig.Length, pkey.Handle));
			return ret == 1;
		}
开发者ID:wow4all,项目名称:mooege,代码行数:25,代码来源:MessageDigest.cs

示例14: CanCreatePKCS12

		public void CanCreatePKCS12() {
			using (BIO bio = new BIO(LoadBytes(Resources.ServerPfx))) {
				using (var pfx = new PKCS12(bio, password)) {
					using (var new_pfx = new PKCS12(password, pfx.PrivateKey, pfx.Certificate, pfx.CACertificates)) {
						TestCert(new_pfx.Certificate, "CN=localhost", "CN=Root", 1235);
					}
				}
			}
		}
开发者ID:challal,项目名称:scallion,代码行数:9,代码来源:TestX509Certificate.cs

示例15: CanLoadFromPCKS12

		public void CanLoadFromPCKS12()
		{
			using (BIO bio = new BIO(LoadBytes(Resources.ServerPfx))) {
				using (X509Certificate cert = X509Certificate.FromPKCS12(bio, password)) {
					TestCert(cert, "CN=localhost", "CN=Root", 1235);
				}
			}
		}
开发者ID:challal,项目名称:scallion,代码行数:8,代码来源:TestX509Certificate.cs


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