• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TlsContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Chacha20Poly1305

        /// <exception cref="IOException"></exception>
        public Chacha20Poly1305(TlsContext context)
        {
            if (!TlsUtilities.IsTlsV12(context))
                throw new TlsFatalAlert(AlertDescription.internal_error);

            this.context = context;

            byte[] key_block = TlsUtilities.CalculateKeyBlock(context, 64);

            KeyParameter client_write_key = new KeyParameter(key_block, 0, 32);
            KeyParameter server_write_key = new KeyParameter(key_block, 32, 32);

            this.encryptCipher = new ChaChaEngine(20);
            this.decryptCipher = new ChaChaEngine(20);

            KeyParameter encryptKey, decryptKey;
            if (context.IsServer)
            {
                encryptKey = server_write_key;
                decryptKey = client_write_key;
            }
            else
            {
                encryptKey = client_write_key;
                decryptKey = server_write_key;
            }

            byte[] dummyNonce = new byte[8];

            this.encryptCipher.Init(true, new ParametersWithIV(encryptKey, dummyNonce));
            this.decryptCipher.Init(false, new ParametersWithIV(decryptKey, dummyNonce));
        }
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:33,代码来源:Chacha20Poly1305.cs


示例2: TlsServerHello

		public TlsServerHello (TlsContext context, TlsBuffer incoming)
			: base (HandshakeType.ServerHello)
		{
			ServerProtocol = (TlsProtocolCode)incoming.ReadInt16 ();

			Read (incoming);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:7,代码来源:TlsServerHello.cs


示例3: ReadMessage

		public static HandshakeMessage ReadMessage (TlsContext context, HandshakeType handshakeType, TlsBuffer incoming)
		{
			HandshakeMessage message;
			switch (handshakeType) {
			case HandshakeType.HelloRequest:
				message = new TlsHelloRequest ();
				break;
			case HandshakeType.ServerHello:
				return new TlsServerHello (context, incoming);
			case HandshakeType.Certificate:
				return new TlsCertificate (incoming);
			case HandshakeType.ServerHelloDone:
				message = new TlsServerHelloDone ();
				break;
			case HandshakeType.Finished:
				return new TlsFinished (incoming);
			case HandshakeType.ClientHello:
				return new TlsClientHello (context, incoming);
			case HandshakeType.ClientKeyExchange:
				return new TlsClientKeyExchange (context, incoming);
			case HandshakeType.CertificateRequest:
				return new TlsCertificateRequest (context.NegotiatedProtocol, incoming);
			case HandshakeType.CertificateVerify:
				return new TlsCertificateVerify (context.NegotiatedProtocol, incoming);
			case HandshakeType.ServerKeyExchange:
				return new TlsServerKeyExchange (context, incoming);
			default:
				throw new TlsException (AlertDescription.UnexpectedMessage, "Unknown server handshake message received: {0}", handshakeType);
			}

			message.Read (incoming);
			return message;
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:33,代码来源:HandshakeMessage.cs


示例4: TlsClientHello

		public TlsClientHello (TlsContext context, TlsBuffer incoming)
			: base (HandshakeType.ClientHello)
		{
			ClientProtocol = (TlsProtocolCode)incoming.ReadInt16 ();

			Read (incoming);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:7,代码来源:TlsClientHello.cs


示例5: DiffieHellmanKeyExchange

		public DiffieHellmanKeyExchange (TlsContext ctx)
		{
			this.protocol = ctx.NegotiatedProtocol;

			switch (protocol) {
			case TlsProtocolCode.Tls12:
				Signature = new SignatureTls12 (ctx.Session.ServerSignatureAlgorithm);
				break;
			case TlsProtocolCode.Tls10:
				Signature = new SignatureTls10 ();
				break;
			case TlsProtocolCode.Tls11:
				Signature = new SignatureTls11 ();
				break;
			default:
				throw new NotSupportedException ();
			}

			dh = new DiffieHellmanManaged ();
			Y = dh.CreateKeyExchange ();
			var dhparams = dh.ExportParameters (true);
			P = dhparams.P;
			G = dhparams.G;

			using (var buffer = CreateParameterBuffer (ctx.HandshakeParameters))
				Signature.Create (buffer, ctx.Configuration.PrivateKey);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:27,代码来源:DiffieHellmanKeyExchange.cs


示例6: GenerateClient

		public override void GenerateClient (TlsContext ctx)
		{
			// Compute pre master secret
			using (var preMasterSecret = ctx.Session.GetSecureRandomBytes (48)) {
				preMasterSecret.Buffer [0] = (byte)((short)ctx.Configuration.RequestedProtocol >> 8);
				preMasterSecret.Buffer [1] = (byte)ctx.Configuration.RequestedProtocol;

				RSA rsa = null;
				// Create a new RSA key
				var serverCertificates = ctx.Session.PendingCrypto.ServerCertificates;
				if (serverCertificates == null || serverCertificates.Count == 0) {
					// FIXME: Should have received ServerKeyExchange message.
					throw new TlsException (AlertDescription.IlegalParameter);
				} else {
					rsa = new RSAManaged (serverCertificates [0].RSA.KeySize);
					rsa.ImportParameters (serverCertificates [0].RSA.ExportParameters (false));
				}

				ComputeMasterSecret (ctx, preMasterSecret);

				// Encrypt premaster_sercret
				var formatter = new RSAPKCS1KeyExchangeFormatter (rsa);
				encryptedPreMasterSecret = formatter.CreateKeyExchange (preMasterSecret.Buffer);
				rsa.Clear ();
			}
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:26,代码来源:RSAKeyExchange.cs


示例7: LoadEncryptionCredentials

        internal static TlsEncryptionCredentials LoadEncryptionCredentials(TlsContext context,
            string[] certResources, string keyResource)
        {
            Certificate certificate = LoadCertificateChain(certResources);
            AsymmetricKeyParameter privateKey = LoadPrivateKeyResource(keyResource);

            return new DefaultTlsEncryptionCredentials(context, certificate, privateKey);
        }
开发者ID:andibadra,项目名称:bc-csharp,代码行数:8,代码来源:TlsTestUtilities.cs


示例8: CreateClient

		internal static RenegotiationExtension CreateClient (TlsContext context)
		{
			if (!context.Session.SecureRenegotiation && (context.Configuration.RenegotiationFlags & RenegotiationFlags.SendClientHelloExtension) == 0)
				return null;

			context.HandshakeParameters.RequestedSecureNegotiation = true;
			return new RenegotiationExtension (context.Session.ClientVerifyData);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:8,代码来源:RenegotiationExtension.cs


示例9: LoadSignerCredentials

        internal static TlsSignerCredentials LoadSignerCredentials(TlsContext context, string[] certResources,
            string keyResource, SignatureAndHashAlgorithm signatureAndHashAlgorithm)
        {
            Certificate certificate = LoadCertificateChain(certResources);
            AsymmetricKeyParameter privateKey = LoadPrivateKeyResource(keyResource);

            return new DefaultTlsSignerCredentials(context, certificate, privateKey, signatureAndHashAlgorithm);
        }
开发者ID:andibadra,项目名称:bc-csharp,代码行数:8,代码来源:TlsTestUtilities.cs


示例10: TlsAeadCipher

        /// <exception cref="IOException"></exception>
        public TlsAeadCipher(TlsContext context, IAeadBlockCipher clientWriteCipher, IAeadBlockCipher serverWriteCipher,
            int cipherKeySize, int macSize)
        {
            if (!TlsUtilities.IsTlsV12(context))
                throw new TlsFatalAlert(AlertDescription.internal_error);

            this.context = context;
            this.macSize = macSize;

            // NOTE: Valid for RFC 5288/6655 ciphers but may need review for other AEAD ciphers
            this.nonce_explicit_length = 8;

            // TODO SecurityParameters.fixed_iv_length
            int fixed_iv_length = 4;

            int key_block_size = (2 * cipherKeySize) + (2 * fixed_iv_length);

            byte[] key_block = TlsUtilities.CalculateKeyBlock(context, key_block_size);

            int offset = 0;

            KeyParameter client_write_key = new KeyParameter(key_block, offset, cipherKeySize);
            offset += cipherKeySize;
            KeyParameter server_write_key = new KeyParameter(key_block, offset, cipherKeySize);
            offset += cipherKeySize;
            byte[] client_write_IV = Arrays.CopyOfRange(key_block, offset, offset + fixed_iv_length);
            offset += fixed_iv_length;
            byte[] server_write_IV = Arrays.CopyOfRange(key_block, offset, offset + fixed_iv_length);
            offset += fixed_iv_length;

            if (offset != key_block_size)
                throw new TlsFatalAlert(AlertDescription.internal_error);

            KeyParameter encryptKey, decryptKey;
            if (context.IsServer)
            {
                this.encryptCipher = serverWriteCipher;
                this.decryptCipher = clientWriteCipher;
                this.encryptImplicitNonce = server_write_IV;
                this.decryptImplicitNonce = client_write_IV;
                encryptKey = server_write_key;
                decryptKey = client_write_key;
            }
            else
            {
                this.encryptCipher = clientWriteCipher;
                this.decryptCipher = serverWriteCipher;
                this.encryptImplicitNonce = client_write_IV;
                this.decryptImplicitNonce = server_write_IV;
                encryptKey = client_write_key;
                decryptKey = server_write_key;
            }

            byte[] dummyNonce = new byte[fixed_iv_length + nonce_explicit_length];

            this.encryptCipher.Init(true, new AeadParameters(encryptKey, 8 * macSize, dummyNonce));
            this.decryptCipher.Init(false, new AeadParameters(decryptKey, 8 * macSize, dummyNonce));
        }
开发者ID:ubberkid,项目名称:PeerATT,代码行数:59,代码来源:TlsAeadCipher.cs


示例11: Init

        internal virtual void Init(TlsContext context)
        {
            this.mReadCipher = new TlsNullCipher(context);
            this.mWriteCipher = this.mReadCipher;
            this.mHandshakeHash = new DeferredHash();
            this.mHandshakeHash.Init(context);

            SetPlaintextLimit(DEFAULT_PLAINTEXT_LIMIT);
        }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:9,代码来源:RecordStream.cs


示例12: Init

        public override void Init(TlsContext context)
        {
            base.Init(context);

            if (this.mTlsSigner != null)
            {
                this.mTlsSigner.Init(context);
            }
        }
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:9,代码来源:TlsDHKeyExchange.cs


示例13: CreateCipher

 /// <exception cref="IOException"></exception>
 public override TlsCipher CreateCipher(TlsContext context, int encryptionAlgorithm, int macAlgorithm)
 {
     switch (encryptionAlgorithm)
     {
     case EncryptionAlgorithm.cls_3DES_EDE_CBC:
         return CreateDesEdeCipher(context, macAlgorithm);
     case EncryptionAlgorithm.AES_128_CBC:
         return CreateAESCipher(context, 16, macAlgorithm);
     case EncryptionAlgorithm.AES_128_CCM:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Aes_Ccm(context, 16, 16);
     case EncryptionAlgorithm.AES_128_CCM_8:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Aes_Ccm(context, 16, 8);
     case EncryptionAlgorithm.AES_128_GCM:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Aes_Gcm(context, 16, 16);
     case EncryptionAlgorithm.AES_128_OCB_TAGLEN96:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Aes_Ocb(context, 16, 12);
     case EncryptionAlgorithm.AES_256_CBC:
         return CreateAESCipher(context, 32, macAlgorithm);
     case EncryptionAlgorithm.AES_256_CCM:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Aes_Ccm(context, 32, 16);
     case EncryptionAlgorithm.AES_256_CCM_8:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Aes_Ccm(context, 32, 8);
     case EncryptionAlgorithm.AES_256_GCM:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Aes_Gcm(context, 32, 16);
     case EncryptionAlgorithm.AES_256_OCB_TAGLEN96:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Aes_Ocb(context, 32, 12);
     case EncryptionAlgorithm.CAMELLIA_128_CBC:
         return CreateCamelliaCipher(context, 16, macAlgorithm);
     case EncryptionAlgorithm.CAMELLIA_128_GCM:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Camellia_Gcm(context, 16, 16);
     case EncryptionAlgorithm.CAMELLIA_256_CBC:
         return CreateCamelliaCipher(context, 32, macAlgorithm);
     case EncryptionAlgorithm.CAMELLIA_256_GCM:
         // NOTE: Ignores macAlgorithm
         return CreateCipher_Camellia_Gcm(context, 32, 16);
     case EncryptionAlgorithm.CHACHA20_POLY1305:
         // NOTE: Ignores macAlgorithm
         return CreateChaCha20Poly1305(context);
     case EncryptionAlgorithm.NULL:
         return CreateNullCipher(context, macAlgorithm);
     case EncryptionAlgorithm.RC4_128:
         return CreateRC4Cipher(context, 16, macAlgorithm);
     case EncryptionAlgorithm.SEED_CBC:
         return CreateSeedCipher(context, macAlgorithm);
     default:
         throw new TlsFatalAlert(AlertDescription.internal_error);
     }
 }
开发者ID:gkardava,项目名称:WinPass,代码行数:58,代码来源:DefaultTlsCipherFactory.cs


示例14: GenerateClient

		public override void GenerateClient (TlsContext ctx)
		{
			using (var dh = new DiffieHellmanManaged (P, G, 0)) {
				using (var X = new SecureBuffer (dh.DecryptKeyExchange (Y))) {
					Y = dh.CreateKeyExchange ();
					ComputeMasterSecret (ctx, X);
				}
			}
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:9,代码来源:DiffieHellmanKeyExchange.cs


示例15: GenerateClient

		public override void GenerateClient (TlsContext context)
		{
			GenerateKeyPair (context, domainParameters, out clientQ, out clientD);
			clientKey = ExternalizeKey (clientQ);

			var agreement = CalculateAgreement (serverQ, clientD);
			using (var preMaster = new SecureBuffer (agreement.ToByteArrayUnsigned ()))
				ComputeMasterSecret (context, preMaster);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:9,代码来源:EllipticCurveKeyExchange.cs


示例16: HandleClient

		public override void HandleClient (TlsContext context, KeyExchange clientExchange)
		{
			var clientKey = ((EllipticCurveKeyExchange)clientExchange).clientKey;

			clientQ = domainParameters.Curve.DecodePoint (clientKey);

			var agreement = CalculateAgreement (clientQ, serverD);
			using (var preMaster = new SecureBuffer (agreement.ToByteArrayUnsigned ()))
				ComputeMasterSecret (context, preMaster);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:10,代码来源:EllipticCurveKeyExchange.cs


示例17: Parse

 /**
  * Parse a {@link DigitallySigned} from a {@link Stream}.
  * 
  * @param context
  *            the {@link TlsContext} of the current connection.
  * @param input
  *            the {@link Stream} to parse from.
  * @return a {@link DigitallySigned} object.
  * @throws IOException
  */
 public static DigitallySigned Parse(TlsContext context, Stream input)
 {
     SignatureAndHashAlgorithm algorithm = null;
     if (TlsUtilities.IsTlsV12(context))
     {
         algorithm = SignatureAndHashAlgorithm.Parse(input);
     }
     byte[] signature = TlsUtilities.ReadOpaque16(input);
     return new DigitallySigned(algorithm, signature);
 }
开发者ID:JohnMalmsteen,项目名称:mobile-apps-tower-defense,代码行数:20,代码来源:DigitallySigned.cs


示例18: ComputeMasterSecret

		void ComputeMasterSecret (DisposeContext d, TlsContext ctx, SecureBuffer preMasterSecret)
		{
			// Compute ClientRandom + ServerRandom
			int clen = ctx.HandshakeParameters.ClientRandom.Size;
			int slen = ctx.HandshakeParameters.ServerRandom.Size;
			int rlen = clen + slen;
			var cs = d.CreateBuffer (rlen);
			Buffer.BlockCopy (ctx.HandshakeParameters.ClientRandom.Buffer, 0, cs.Buffer, 0, clen);
			Buffer.BlockCopy (ctx.HandshakeParameters.ServerRandom.Buffer, 0, cs.Buffer, clen, slen);

			// Server Random + Client Random
			var sc = d.CreateBuffer (rlen);
			Buffer.BlockCopy (ctx.HandshakeParameters.ServerRandom.Buffer, 0, sc.Buffer, 0, slen);
			Buffer.BlockCopy (ctx.HandshakeParameters.ClientRandom.Buffer, 0, sc.Buffer, slen, clen);

			// Create master secret
			var crypto = ctx.Session.PendingCrypto;
			crypto.MasterSecret = crypto.Cipher.PRF.ComputeMasterSecret (preMasterSecret, cs);

			#if DEBUG_FULL
			if (ctx.EnableDebugging) {
				DebugHelper.WriteLine ("CS", cs);
				DebugHelper.WriteLine ("SC", sc);
				DebugHelper.WriteLine ("PRE-MASTER", preMasterSecret);
				DebugHelper.WriteLine ("MASTER SECRET", crypto.MasterSecret.Buffer);
			}
			#endif

			var keyBlock = crypto.Cipher.PRF.ComputeKeyExpansion (d, crypto.MasterSecret, sc, crypto.Cipher.KeyBlockSize);

			#if DEBUG_FULL
			if (ctx.EnableDebugging) {
				DebugHelper.WriteLine ("KEY BLOCK SIZE: {0}", crypto.Cipher.KeyBlockSize);
				DebugHelper.WriteLine ("KEY BLOCK", keyBlock.Buffer);
			}
			#endif

			crypto.ClientWriteMac = keyBlock.ReadSecureBuffer (crypto.Cipher.HashSize);
			crypto.ServerWriteMac = keyBlock.ReadSecureBuffer (crypto.Cipher.HashSize);
			crypto.ClientWriteKey = keyBlock.ReadSecureBuffer (crypto.Cipher.KeyMaterialSize);
			crypto.ServerWriteKey = keyBlock.ReadSecureBuffer (crypto.Cipher.KeyMaterialSize);

			if (crypto.Cipher.HasFixedIV) {
				crypto.ClientWriteIV = keyBlock.ReadSecureBuffer (crypto.Cipher.FixedIvSize);
				crypto.ServerWriteIV = keyBlock.ReadSecureBuffer (crypto.Cipher.FixedIvSize);

				#if DEBUG_FULL
				if (ctx.EnableDebugging) {
					DebugHelper.WriteLine ("CLIENT IV", crypto.ClientWriteIV.Buffer);
					DebugHelper.WriteLine ("SERVER IV", crypto.ServerWriteIV.Buffer);
				}
				#endif
			}
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:54,代码来源:KeyExchange.cs


示例19: Encode

        /**
         * Encode this {@link HeartbeatMessage} to a {@link Stream}.
         * 
         * @param output
         *            the {@link Stream} to encode to.
         * @throws IOException
         */
        public virtual void Encode(TlsContext context, Stream output)
        {
            TlsUtilities.WriteUint8(mType, output);

            TlsUtilities.CheckUint16(mPayload.Length);
            TlsUtilities.WriteUint16(mPayload.Length, output);
            output.Write(mPayload, 0, mPayload.Length);

            byte[] padding = new byte[mPaddingLength];
            context.NonceRandomGenerator.NextBytes(padding);
            output.Write(padding, 0, padding.Length);
        }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:19,代码来源:HeartbeatMessage.cs


示例20: Chacha20Poly1305

        /// <exception cref="IOException"></exception>
        public Chacha20Poly1305(TlsContext context)
        {
            if (!TlsUtilities.IsTlsV12(context))
                throw new TlsFatalAlert(AlertDescription.internal_error);

            this.context = context;

            int cipherKeySize = 32;
            // TODO SecurityParameters.fixed_iv_length
            int fixed_iv_length = 12;
            // TODO SecurityParameters.record_iv_length = 0

            int key_block_size = (2 * cipherKeySize) + (2 * fixed_iv_length);

            byte[] key_block = TlsUtilities.CalculateKeyBlock(context, key_block_size);

            int offset = 0;

            KeyParameter client_write_key = new KeyParameter(key_block, offset, cipherKeySize);
            offset += cipherKeySize;
            KeyParameter server_write_key = new KeyParameter(key_block, offset, cipherKeySize);
            offset += cipherKeySize;
            byte[] client_write_IV = Arrays.CopyOfRange(key_block, offset, offset + fixed_iv_length);
            offset += fixed_iv_length;
            byte[] server_write_IV = Arrays.CopyOfRange(key_block, offset, offset + fixed_iv_length);
            offset += fixed_iv_length;

            if (offset != key_block_size)
                throw new TlsFatalAlert(AlertDescription.internal_error);

            this.encryptCipher = new ChaCha7539Engine();
            this.decryptCipher = new ChaCha7539Engine();

            KeyParameter encryptKey, decryptKey;
            if (context.IsServer)
            {
                encryptKey = server_write_key;
                decryptKey = client_write_key;
                this.encryptIV = server_write_IV;
                this.decryptIV = client_write_IV;
            }
            else
            {
                encryptKey = client_write_key;
                decryptKey = server_write_key;
                this.encryptIV = client_write_IV;
                this.decryptIV = server_write_IV;
            }

            this.encryptCipher.Init(true, new ParametersWithIV(encryptKey, encryptIV));
            this.decryptCipher.Init(false, new ParametersWithIV(decryptKey, decryptIV));
        }
开发者ID:gkardava,项目名称:WinPass,代码行数:53,代码来源:Chacha20Poly1305.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Tnum类代码示例发布时间:2022-05-24
下一篇:
C# TitleInfo类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap