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


C# BigInteger.ToByteArray方法代码示例

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


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

示例1: KeyExchangeEcdhInitMessage

 /// <summary>
 /// Initializes a new instance of the <see cref="KeyExchangeEcdhInitMessage"/> class.
 /// </summary>
 /// <param name="clientExchangeValue">The client exchange value.</param>
 public KeyExchangeEcdhInitMessage(BigInteger d, BigInteger Q)
 {
     var a = d.ToByteArray().Reverse();
     var b = Q.ToByteArray().Reverse();
     var data = new List<byte>();
     data.Add(0x04);
     data.AddRange(d.ToByteArray().Reverse());
     data.AddRange(Q.ToByteArray().Reverse());
     this.QC = data.ToArray();
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:14,代码来源:KeyExchangeEcdhInitMessage.cs

示例2: WriteBigInt1

        /// <summary>
        /// Reads next mpint1 (SSH1) data type from internal buffer.
        /// </summary>
        /// <returns>mpint read.</returns>
        protected void WriteBigInt1(BigInteger bigInt)
        {
            this.Write((UInt16)bigInt.BitLength);

            var bytes = bigInt.ToByteArray().Reverse();
            this.Write(bytes);
        }
开发者ID:yiyi99,项目名称:RemoteTerminal,代码行数:11,代码来源:PrivateKeyAgentMessage.cs

示例3: FromLongTests

 public void FromLongTests(long l, byte[] expectedBytes)
 {
     BigInteger bi = new BigInteger(l);
     byte[] bytes = bi.ToByteArray();
     Assert.Equal(expectedBytes, bytes);
     BigInteger bi2 = new BigInteger(bytes);
     Assert.Equal(bi, bi2);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:ToByteArray.cs

示例4: FromIntTests

 public void FromIntTests(int i, byte[] expectedBytes)
 {
     BigInteger bi = new BigInteger(i);
     byte[] bytes = bi.ToByteArray();
     Assert.Equal(expectedBytes, bytes);
     BigInteger bi2 = new BigInteger(bytes);
     Assert.Equal(bi, bi2);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:ToByteArray.cs

示例5: DerInteger

		public DerInteger(
            BigInteger value)
        {
            if (value == null)
                throw new ArgumentNullException("value");

			bytes = value.ToByteArray();
        }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:8,代码来源:DerInteger.cs

示例6: KeyExchangeDhInitMessage

        /// <summary>
        /// Initializes a new instance of the <see cref="KeyExchangeDhInitMessage"/> class.
        /// </summary>
        /// <param name="clientExchangeValue">The client exchange value.</param>
        public KeyExchangeDhInitMessage(BigInteger clientExchangeValue)
        {
#if TUNING
            _eBytes = clientExchangeValue.ToByteArray().Reverse();
#else
            E = clientExchangeValue;
#endif
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:12,代码来源:KeyExchangeDhInitMessage.cs

示例7: Agree

        public byte[] Agree()
        {
            IBasicAgreement iba;
            iba = AgreementUtilities.GetBasicAgreement("DH");
            iba.Init(_kp.Private);

            _agreement = iba.CalculateAgreement(RemotePublicKey);
            return _agreement.ToByteArray();
        }
开发者ID:soshimozi,项目名称:SocketServer,代码行数:9,代码来源:DHProvider.cs

示例8: RunByteExplicitCastFromBigIntegerTests

        public static void RunByteExplicitCastFromBigIntegerTests()
        {
            Byte value = 0;
            BigInteger bigInteger;

            // Byte Explicit Cast from BigInteger: Random value < Byte.MinValue
            bigInteger = GenerateRandomBigIntegerLessThan(Byte.MinValue, s_random);
            value = bigInteger.ToByteArray()[0];
            Assert.Throws<OverflowException>(() => VerifyByteExplicitCastFromBigInteger(value, bigInteger));

            // Byte Explicit Cast from BigInteger: Byte.MinValue - 1
            bigInteger = new BigInteger(Byte.MinValue);
            bigInteger -= BigInteger.One;
            value = bigInteger.ToByteArray()[0];
            Assert.Throws<OverflowException>(() => VerifyByteExplicitCastFromBigInteger(value, bigInteger));

            // Byte Explicit Cast from BigInteger: Byte.MinValue
            VerifyByteExplicitCastFromBigInteger(Byte.MinValue);

            // Byte Explicit Cast from BigInteger: 0
            VerifyByteExplicitCastFromBigInteger(0);

            // Byte Explicit Cast from BigInteger: 1
            VerifyByteExplicitCastFromBigInteger(1);

            // Byte Explicit Cast from BigInteger: Random Positive
            for (int i = 0; i < NumberOfRandomIterations; ++i)
            {
                VerifyByteExplicitCastFromBigInteger((Byte)s_random.Next(1, Byte.MaxValue));
            }

            // Byte Explicit Cast from BigInteger: Byte.MaxValue + 1
            bigInteger = new BigInteger(Byte.MaxValue);
            bigInteger += BigInteger.One;
            value = bigInteger.ToByteArray()[0];
            Assert.Throws<OverflowException>(() => VerifyByteExplicitCastFromBigInteger(value, bigInteger));

            // Byte Explicit Cast from BigInteger: Random value > Byte.MaxValue
            bigInteger = GenerateRandomBigIntegerGreaterThan(Byte.MaxValue, s_random);
            value = bigInteger.ToByteArray()[0];
            Assert.Throws<OverflowException>(() => VerifyByteExplicitCastFromBigInteger(value, bigInteger));
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:42,代码来源:cast_from.cs

示例9: KeyExchangeEcdhInitMessage

        /// <summary>
        /// Initializes a new instance of the <see cref="KeyExchangeEcdhInitMessage"/> class.
        /// </summary>
        public KeyExchangeEcdhInitMessage(BigInteger d, BigInteger q)
        {
            var dBytes = d.ToByteArray().Reverse();
            var qBytes = q.ToByteArray().Reverse();

            var data = new byte[dBytes.Length + qBytes.Length + 1];
            data[0] = 0x04;
            Buffer.BlockCopy(dBytes, 0, data, 1, dBytes.Length);
            Buffer.BlockCopy(qBytes, 0, data, dBytes.Length + 1, qBytes.Length);
            QC = data;
        }
开发者ID:sshnet,项目名称:SSH.NET,代码行数:14,代码来源:KeyExchangeEcdhInitMessage.cs

示例10: KeyExchangeEcdhInitMessage

        /// <summary>
        /// Initializes a new instance of the <see cref="KeyExchangeEcdhInitMessage"/> class.
        /// </summary>
        public KeyExchangeEcdhInitMessage(BigInteger d, BigInteger q)
        {
#if TUNING
            var dBytes = d.ToByteArray().Reverse();
            var qBytes = q.ToByteArray().Reverse();

            var data = new byte[dBytes.Length + qBytes.Length + 1];
            data[0] = 0x04;
            Buffer.BlockCopy(dBytes, 0, data, 1, dBytes.Length);
            Buffer.BlockCopy(qBytes, 0, data, dBytes.Length + 1, qBytes.Length);
            QC = data;
#else
            var dBytes = d.ToByteArray();
            var qBytes = q.ToByteArray();

            var data = new List<byte>();
            data.Add(0x04);
            data.AddRange(d.ToByteArray().Reverse());
            data.AddRange(q.ToByteArray().Reverse());
            QC = data.ToArray();
#endif
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:25,代码来源:KeyExchangeEcdhInitMessage.cs

示例11: DecryptSsh1

        public byte[] DecryptSsh1(BigInteger e, BigInteger n, BigInteger encryptedChallenge, byte[] sessionId)
        {
            var decryptKey = GetKey(e, n);

            if (decryptKey == null)
            {
                return null;
            }

            RsaCipher cipher = new RsaCipher((RsaKey)decryptKey.Key.Key);
            byte[] decryptedChallenge = cipher.Decrypt(encryptedChallenge.ToByteArray().Reverse().ToArray());

            var md5 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
            byte[] response;
            CryptographicBuffer.CopyToByteArray(md5.HashData(CryptographicBuffer.CreateFromByteArray(decryptedChallenge.Concat(sessionId).ToArray())), out response);
            return response;
        }
开发者ID:yiyi99,项目名称:RemoteTerminal,代码行数:17,代码来源:PrivateKeyAgent.cs

示例12: VerifyBigIntegerUsingIdentities

        private static void VerifyBigIntegerUsingIdentities(BigInteger bigInteger, bool isZero)
        {
            BigInteger tempBigInteger = new BigInteger(bigInteger.ToByteArray());

            Assert.Equal(bigInteger, tempBigInteger);

            if (isZero)
            {
               Assert.Equal(BigInteger.Zero, bigInteger);
            }
            else
            {
               Assert.NotEqual(BigInteger.Zero, bigInteger);

                // x/x = 1
               Assert.Equal(BigInteger.One, bigInteger / bigInteger);
            }

            // (x + 1) - 1 = x
            Assert.Equal(bigInteger, (bigInteger + BigInteger.One) - BigInteger.One);

            // (x + 1) - x = 1
            Assert.Equal(BigInteger.One, (bigInteger + BigInteger.One) - bigInteger);

            // x - x = 0
            Assert.Equal(BigInteger.Zero, bigInteger - bigInteger);

            // x + x = 2x
            Assert.Equal(2 * bigInteger, bigInteger + bigInteger);

            // x/1 = x
            Assert.Equal(bigInteger, bigInteger / BigInteger.One);

            // 1 * x = x
            Assert.Equal(bigInteger, BigInteger.One * bigInteger);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:36,代码来源:cast_to.cs

示例13: Write

 /// <summary>
 /// Writes INTEGER data into internal buffer.
 /// </summary>
 /// <param name="data">BigInteger data to write.</param>
 public void Write(BigInteger data)
 {
     var bytes = data.ToByteArray().Reverse().ToList();
     this._data.Add(INTEGER);
     var length = this.GetLength(bytes.Count);
     this.WriteBytes(length);
     this.WriteBytes(bytes);
 }
开发者ID:ElanHasson,项目名称:SSIS-Extensions,代码行数:12,代码来源:DerData.cs

示例14: Write

        /// <summary>
        /// Writes INTEGER data into internal buffer.
        /// </summary>
        /// <param name="data">BigInteger data to write.</param>
        public void Write(BigInteger data)
        {
#if TUNING
            var bytes = data.ToByteArray().Reverse().ToList();
#else
            var bytes = data.ToByteArray().Reverse().ToList();
#endif
            _data.Add(Integer);
            var length = GetLength(bytes.Count);
            WriteBytes(length);
            WriteBytes(bytes);
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:16,代码来源:DerData.cs

示例15: MakeInt32

        private int MakeInt32(BigInteger input)
        {
            int output;

            if (input < 0)
            {
                input = -input;
            }
            input = input + int.MaxValue;

            byte[] temp = input.ToByteArray();
            temp[1] = 0;
            temp[2] = 0;
            temp[3] = 0;

            output = BitConverter.ToInt32(temp, 0);
            if (output == 0)
            {
                output = 1;
            }

            return output;
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:23,代码来源:Driver.cs


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