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


C# BigInteger.ToByteArray方法代码示例

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


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

示例1: EncodeInt

        public byte[] EncodeInt(BigInteger bigInt)
        {
            byte[] ret = new byte[32];

            for (int i = 0; i < ret.Length; i++)
            {
                if (bigInt.Sign < 0)
                {
                    ret[i] = 0xFF;
                }
                else
                {
                    ret[i] = 0;
                }
            }

            byte[] bytes;

            //It should always be Big Endian.
            if (BitConverter.IsLittleEndian)
            {
                bytes = bigInt.ToByteArray().Reverse().ToArray();
            }
            else
            {
                bytes = bigInt.ToByteArray().ToArray();
            }

            Array.Copy(bytes, 0, ret, 32 - bytes.Length, bytes.Length);

            return ret;
        }
开发者ID:ffabrizio,项目名称:Nethereum,代码行数:32,代码来源:IntTypeEncoder.cs

示例2: ConvertFrom

        public object ConvertFrom(byte[] decimalBuf)
        {
            var bigintBytes = new byte[decimalBuf.Length - 4];
            Array.Copy(decimalBuf, 4, bigintBytes, 0, bigintBytes.Length);
            //Scale representation is an int, but System.Decimal only supports a scale of 1 byte
            var scale = decimalBuf[3];

            Array.Reverse(bigintBytes);
            var bigInteger = new BigInteger(bigintBytes);
            var isNegative = bigInteger < 0;

            bigInteger = BigInteger.Abs(bigInteger);
            bigintBytes = bigInteger.ToByteArray();
            if (bigintBytes.Length > 13 || (bigintBytes.Length == 13 && bigintBytes[12] != 0))
            {
                throw new ArgumentOutOfRangeException(
                    "decimalBuf",
                    "this java.math.BigDecimal is too big to fit into System.Decimal. Think about using other TypeAdapter for java.math.BigDecimal (e.g. J#, IKVM,...)");
            }

            var intArray = new int[3];
            Buffer.BlockCopy(bigintBytes, 0, intArray, 0, Math.Min(12, bigintBytes.Length));

            return new decimal(intArray[0], intArray[1], intArray[2], isNegative, scale);
        }
开发者ID:alprema,项目名称:csharp-driver,代码行数:25,代码来源:DecimalTypeAdapter.cs

示例3: HKeyExchange

        public HKeyExchange(int exponent, string modulus, string privateExponent) :
            this()
        {
            var keys = new RSAParameters();
            Exponent = new BigInteger(exponent);
            keys.Exponent = Exponent.ToByteArray();

            Modulus = BigInteger.Parse("0" + modulus, NumberStyles.HexNumber);
            keys.Modulus = Modulus.ToByteArray();
            Array.Reverse(keys.Modulus);

            if (!string.IsNullOrWhiteSpace(privateExponent))
            {
                PrivateExponent = BigInteger.Parse("0" + privateExponent, NumberStyles.HexNumber);
                keys.D = PrivateExponent.ToByteArray();
                Array.Reverse(keys.D);

                GenerateDHPrimes(256);
                GenerateDHKeys(DHPrime, DHGenerator);
            }

            RSA = new RSACryptoServiceProvider();
            RSA.ImportParameters(keys);

            _blockSize = (RSA.KeySize -
                RSA.LegalKeySizes[0].SkipSize) / 8;
        }
开发者ID:SirJamal,项目名称:Sulakore,代码行数:27,代码来源:HKeyExchange.cs

示例4: EncodeMPBigInteger

 public static byte[] EncodeMPBigInteger(BigInteger value)
 {
     byte[] rawEncoding = value.ToByteArray();
     Array.Reverse(rawEncoding);
     byte[] lengthEncoded = EncodeBEWord((uint)rawEncoding.Length);
     return CombineByteArrays(lengthEncoded, rawEncoding);
 }
开发者ID:jango2015,项目名称:Ironclad,代码行数:7,代码来源:Common.cs

示例5: Encrypt

        public static byte[] Encrypt(byte[] input, BigInteger N, BigInteger E)
        {
            int originalsize = input.Length;
            int inputBlockLength = N.ToByteArray().Length - 1;
            int encodedBlockLength = inputBlockLength + 1;
            int blocksCount = input.Length / inputBlockLength;
            if (input.Length % inputBlockLength != 0)
            {
                blocksCount++;
                Array.Resize(ref input, blocksCount * inputBlockLength);
            }
            int headerSize = 4;
            byte[] encodedResult = new byte[blocksCount * encodedBlockLength + headerSize];
            Array.Copy(BitConverter.GetBytes(originalsize), encodedResult, 4);
            for (int i = 0; i < (input.Length / inputBlockLength) + 1; i++)
            {
                byte[] block = new byte[inputBlockLength];
                Array.Copy(input, i + inputBlockLength, block, 0, inputBlockLength);
                BigInteger message = new BigInteger(block);
                byte[] bytes = BigInteger.ModPow(message, E, N).ToByteArray();
                Array.Copy(bytes, 0, encodedResult, headerSize + i * encodedBlockLength, bytes.Length);
            }

            return encodedResult;
        }
开发者ID:SergeHill,项目名称:CryptproSH,代码行数:25,代码来源:RSA.cs

示例6: RSA

        /// <summary>
        /// Creates instance of RSA cryptography algorithm class
        /// </summary>
        /// <param name="p">Prime number P</param>
        /// <param name="q">Prime number Q</param>
        public RSA(BigInteger p, BigInteger q)
        {
            P = p;
            Q = q;

            KeySize = (p > q) ? (p.ToByteArray().Length * 8) : (q.ToByteArray().Length * 8);
        }
开发者ID:DVitinnik,项目名称:UniversityApps,代码行数:12,代码来源:RSA.cs

示例7: BigIntegerConstruction

 public void BigIntegerConstruction(BigInteger bi)
 {
     var biBytes = new byte[32];
     bi.ToByteArray().CopyTo(biBytes, 0);
     var hash = new Hash256(bi);
     Assert.AreElementsEqual(biBytes, hash.Bytes);
 }
开发者ID:neoeinstein,项目名称:xpdm.Bitcoin,代码行数:7,代码来源:Hash256Test.cs

示例8: Base58ToByteArray

        public static byte[] Base58ToByteArray(string base58)
        {
            BigInteger bi2 = new BigInteger(0);
            string b58 =new string(B58);

            foreach (char c in base58)
            {
                if (b58.IndexOf(c) != -1)
                {
                    bi2 = BigInteger.Multiply(bi2, Big58);
                    bi2 = BigInteger.Add(bi2, b58.IndexOf(c));
                }
                else
                    return null;
            }

            byte[] bb = bi2.ToByteArray();
            if (bb[bb.Length-1]==0)
            {
                byte[] withoutZero = new byte[bb.Length-1];
                Buffer.BlockCopy(bb, 0, withoutZero, 0, bb.Length - 1);
                bb = withoutZero;
            }
            Array.Reverse(bb);
            return bb;
        }
开发者ID:sharpbitmessage,项目名称:SharpBitmessage,代码行数:26,代码来源:Base58.cs

示例9: EncodeInt

 public static byte[] EncodeInt(BigInteger y)
 {
     byte[] nin = y.ToByteArray();
     var nout = new byte[Math.Max(nin.Length, 32)];
     Array.Copy(nin, nout, nin.Length);
     return nout;
 }
开发者ID:hanswolff,项目名称:ed25519,代码行数:7,代码来源:Ed25519.cs

示例10: encryptFile

 private void encryptFile(object sender, RoutedEventArgs e)
 {
     var bytes = File.ReadAllBytes(filePathOpen.Text);
     var open_key = File.ReadAllLines(SenderPath + @"\open_key.txt");
     var D = new BigInteger(open_key[0].Split(' ').Select(a => byte.Parse(a.ToString(), NumberStyles.HexNumber)).ToArray());
     var N = new BigInteger(open_key[1].Split(' ').Select(a => byte.Parse(a.ToString(), NumberStyles.HexNumber)).ToArray());
     var cryptArr = new BigInteger[(bytes.Length / (N.ToByteArray().Length - 1) + 1)];
     for (int i = 0, k = 0; i < bytes.Length; i = i)
     {
         var data = bytes.Skip(i).Take(N.ToByteArray().Length - 1).ToArray();
         cryptArr[k++] = RSAEx.EnCrypt(new BigInteger(data), D, N);
         i += data.Length;
     }
     File.WriteAllLines(filePathEncrypt.Text, cryptArr.Select(intg => string.Join(" ", intg.ToByteArray().Select(a => a.ToString("X")))));
     MessageBox.Show("Шифрование завершено");
 }
开发者ID:klyuchnikov,项目名称:Miszki,代码行数:16,代码来源:MainWindow.xaml.cs

示例11: ConvertTo

        public byte[] ConvertTo(object value)
        {
            TypeSerializer.CheckArgument<decimal>(value);
            var decimalValue = (decimal)value;
            int[] bits = decimal.GetBits(decimalValue);

            int scale = (bits[3] >> 16) & 31;

            byte[] scaleBytes = BeConverter.GetBytes(scale);

            var bigintBytes = new byte[13]; // 13th byte is for making sure that the number is positive
            Buffer.BlockCopy(bits, 0, bigintBytes, 0, 12);

            var bigInteger = new BigInteger(bigintBytes);
            if (decimalValue < 0)
            {
                bigInteger = -bigInteger;
            }

            bigintBytes = bigInteger.ToByteArray();
            Array.Reverse(bigintBytes);

            var resultBytes = new byte[scaleBytes.Length + bigintBytes.Length];
            Array.Copy(scaleBytes, resultBytes, scaleBytes.Length);
            Array.Copy(bigintBytes, 0, resultBytes, scaleBytes.Length, bigintBytes.Length);
            return resultBytes;
        }
开发者ID:alprema,项目名称:csharp-driver,代码行数:27,代码来源:DecimalTypeAdapter.cs

示例12: Push

 public ScriptBuilder Push(BigInteger number)
 {
     if (number == -1) return Add(ScriptOp.OP_1NEGATE);
     if (number == 0) return Add(ScriptOp.OP_0);
     if (number > 0 && number <= 16) return Add(ScriptOp.OP_1 - 1 + (byte)number);
     return Push(number.ToByteArray());
 }
开发者ID:bityuan,项目名称:AntShares,代码行数:7,代码来源:ScriptBuilder.cs

示例13: BigRandom

 private static BigInteger BigRandom(this Random rand, BigInteger max)
 {
     var bytes = max.ToByteArray();
     var maxByte = bytes[bytes.Length - 1];
     rand.NextBytes(bytes);
     bytes[bytes.Length - 1] = (byte)rand.Next(maxByte);
     return new BigInteger(bytes);
 }
开发者ID:EkardNT,项目名称:CS165,代码行数:8,代码来源:Program.cs

示例14: Coprimes

        public Coprimes(BigInteger target, BigInteger min, BigInteger max)
        {
            Target = new BigInteger(target.ToByteArray());
            Min = min;
            Max = max;

            counter = Min;
        }
开发者ID:AdamRakaska,项目名称:Thinq,代码行数:8,代码来源:CoPrimes.cs

示例15: CalculateV

        void CalculateV(BigInteger x, bool calcB)
        {
            v = BigInteger.ModPow(gBN, x, BN);
            V = v.ToByteArray();

            if (calcB)
                CalculateB();
        }
开发者ID:australopitheque,项目名称:Project-WoW,代码行数:8,代码来源:SRP6a.cs


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