當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。