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


C# ByteBuffer.GetNSamples方法代码示例

本文整理汇总了C#中System.ByteBuffer.GetNSamples方法的典型用法代码示例。如果您正苦于以下问题:C# ByteBuffer.GetNSamples方法的具体用法?C# ByteBuffer.GetNSamples怎么用?C# ByteBuffer.GetNSamples使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.GetNSamples方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExpandSHA1

        public byte[] ExpandSHA1(byte[] secret, byte[] seed, int length)
        {
            int hashLength = 20;
            int iterations = (int)(length / hashLength);
            if ((length % hashLength) > 0)
            {
                iterations++;
            }

            ByteBuffer resMacs = new ByteBuffer();
            byte[] bAofi = seed;

            for (int i = 1; i <= iterations; i++)
            {
                ByteBuffer hcseed = new ByteBuffer();
                HMACSHA1 sha = new HMACSHA1(secret);

                byte[] bNextAofi = sha.ComputeHash(bAofi); /// A(1) = HMAC_hash(secret, A(0)),
                /// A(2) = HMAC_hash(secret, A(1)),
                /// etc

                HMACSHA1 sha2 = new HMACSHA1(secret);
                byte[] bComputeNextHashOver = new byte[20 + seed.Length];
                Array.Copy(bNextAofi, 0, bComputeNextHashOver, 0, 20);
                Array.Copy(seed, 0, bComputeNextHashOver, 20, seed.Length);
                byte[] bTotalHashThisIteration = sha2.ComputeHash(bComputeNextHashOver);
                resMacs.AppendData(bTotalHashThisIteration); /// Append it to our total buffer

                bAofi = bNextAofi; /// use next loop

            }

            byte[] res = resMacs.GetNSamples(length);

            return res;
        }
开发者ID:Hitchhikrr,项目名称:Voip,代码行数:36,代码来源:TLSStructures.cs

示例2: ComputeKeys

        public void ComputeKeys(byte[] MasterSecret, byte[] ServerPlusClientRandomKeys)
        {
            // Create keyblock
            ByteBuffer keyBlock = new ByteBuffer();
            byte[] bKEPRF = this.PRF(MasterSecret, "key expansion", ServerPlusClientRandomKeys, this.SecurityParameters.Cipher.KeyBlockSize);
            keyBlock.AppendData(bKEPRF);

            this.ClientWriteMACSecret = keyBlock.GetNSamples(this.SecurityParameters.Cipher.HashSize);
            this.ServerWriteMACSecret = keyBlock.GetNSamples(this.SecurityParameters.Cipher.HashSize);
            this.ClientWriteKey = keyBlock.GetNSamples(this.SecurityParameters.Cipher.KeyMaterialLength);
            this.ServerWriteKey = keyBlock.GetNSamples(this.SecurityParameters.Cipher.KeyMaterialLength);

            if (SocketClient.ShowDebug == true)
            {
                System.Diagnostics.Debug.WriteLine("ClientWriteMACSecret: +++++++++++\r\n{0}\r\n++++++++++++", ByteHelper.HexStringFromByte(this.ClientWriteMACSecret, true, 16));
                System.Diagnostics.Debug.WriteLine("ServerWriteMACSecret: +++++++++++\r\n{0}\r\n++++++++++++", ByteHelper.HexStringFromByte(this.ServerWriteMACSecret, true, 16));
                System.Diagnostics.Debug.WriteLine("ClientWriteKey: +++++++++++\r\n{0}\r\n++++++++++++", ByteHelper.HexStringFromByte(this.ClientWriteKey, true, 16));
                System.Diagnostics.Debug.WriteLine("ServerWriteKey: +++++++++++\r\n{0}\r\n++++++++++++", ByteHelper.HexStringFromByte(this.ServerWriteKey, true, 16));
            }

            //if (!this.IsExportable)
            //{
            if (this.SecurityParameters.Cipher.IVSize != 0)
            {
                this.ClientWriteIV = keyBlock.GetNSamples(this.SecurityParameters.Cipher.IVSize);
                this.ServerWriteIV = keyBlock.GetNSamples(this.SecurityParameters.Cipher.IVSize);
            }
            else
            {
                this.ClientWriteIV = new byte[] { };
                this.ServerWriteIV = new byte[] { };
            }
            //}
            if (SocketClient.ShowDebug == true)
            {
                System.Diagnostics.Debug.WriteLine("ClientWriteIV: +++++++++++\r\n{0}\r\n++++++++++++", ByteHelper.HexStringFromByte(this.ClientWriteIV, true, 16));
                System.Diagnostics.Debug.WriteLine("ServerWriteIV: +++++++++++\r\n{0}\r\n++++++++++++", ByteHelper.HexStringFromByte(this.ServerWriteIV, true, 16));
            }

            //else
            //{
            //    // Generate final write keys
            //    byte[] finalClientWriteKey = PRF(this.Context.ClientWriteKey, "client write key", this.Context.RandomCS, this.ExpandedKeyMaterialSize);
            //    byte[] finalServerWriteKey = PRF(this.Context.ServerWriteKey, "server write key", this.Context.RandomCS, this.ExpandedKeyMaterialSize);

            //    this.Context.ClientWriteKey = finalClientWriteKey;
            //    this.Context.ServerWriteKey = finalServerWriteKey;

            //    if (this.IvSize > 0)
            //    {
            //        // Generate IV block
            //        byte[] ivBlock = PRF(CipherSuite.EmptyArray, "IV block", this.Context.RandomCS, this.IvSize * 2);

            //        // Generate IV keys
            //        this.Context.ClientWriteIV = new byte[this.IvSize];
            //        Buffer.BlockCopy(ivBlock, 0, this.Context.ClientWriteIV, 0, this.Context.ClientWriteIV.Length);

            //        this.Context.ServerWriteIV = new byte[this.IvSize];
            //        Buffer.BlockCopy(ivBlock, this.IvSize, this.Context.ServerWriteIV, 0, this.Context.ServerWriteIV.Length);
            //    }
            //    else
            //    {
            //        this.Context.ClientWriteIV = CipherSuite.EmptyArray;
            //        this.Context.ServerWriteIV = CipherSuite.EmptyArray;
            //    }
            //}

            Initialize(); /// Initialize our cryptographic grind thingies on that thingy
        }
开发者ID:Hitchhikrr,项目名称:Voip,代码行数:69,代码来源:TLSStructures.cs


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