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


C# BigInteger.ToByteArray方法代码示例

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


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

示例1: IntegerToBytes

        public static byte[] IntegerToBytes(
            BigInteger	s,
            int			qLength)
        {
            byte[] bytes = s.ToByteArray();

            if (qLength < bytes.Length)
            {
                byte[] tmp = new byte[qLength];

                Array.Copy(bytes, bytes.Length - tmp.Length, tmp, 0, tmp.Length);

                return tmp;
            }

            if (qLength > bytes.Length)
            {
                byte[] tmp = new byte[qLength];

                Array.Copy(bytes, 0, tmp, tmp.Length - bytes.Length, bytes.Length);

                return tmp;
            }

            return bytes;
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:26,代码来源:X9IntegerConverter.cs

示例2: DerInteger

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

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

示例3: packInto32

		private static string packInto32(BigInteger b) {
			var arr = b.ToByteArray ();
			var start = arr.Length == 33 ? 1 : 0;
			var len = Math.Min (arr.Length, 32);
			var result = new byte[32];

			/* Make sure the integer b takes 32 bytes. */
			Array.Copy (arr, start, result, 32 - len, len);
			/* Convert the array to a hexadecimal string. */
			return BitConverter.ToString (result).Replace ("-", string.Empty).ToLower();
		}
开发者ID:demenvil,项目名称:public,代码行数:11,代码来源:CoinapultECC.cs

示例4: Verify

 public static bool Verify(byte[] data, byte[] sigBytes, BigInteger pub)
 {
     EcdsaSignature signature = EcdsaSignature.DecodeFromDer(sigBytes);
     var signer = new ECDsaSigner();
     ECPoint pubPoint = Secp256K1.Curve().DecodePoint(pub.ToByteArray());
     var parameters = new ECPublicKeyParameters(pubPoint, Secp256K1.Params());
     signer.Init(false, parameters);
     try
     {
         return signer.VerifySignature(data, signature.R, signature.S);
     }
     catch (Exception)
     {
         return false;
     }
 }
开发者ID:kueiwa,项目名称:ripple-cs,代码行数:16,代码来源:KeyPair.cs

示例5: AsUnsignedByteArray

        /**
        * Return the passed in value as an unsigned byte array.
        *
        * @param value value to be converted.
        * @return a byte array without a leading zero byte if present in the signed encoding.
        */
        public static byte[] AsUnsignedByteArray(
			BigInteger value)
        {
            byte[] bytes = value.ToByteArray();

            if (bytes[0] == 0)
            {
                byte[] tmp = new byte[bytes.Length - 1];

                Array.Copy(bytes, 1, tmp, 0, tmp.Length);

                return tmp;
            }

            return bytes;
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:22,代码来源:BigIntegers.cs

示例6: Encode

        /// <summary>
        /// MPI encoded numbers are produced by the OpenSSL BN_bn2mpi function.
        /// They consist of a 4 byte big endian length field, followed by the stated number of bytes representing the number in big endian format (with a sign bit).
        /// </summary>
        /// <param name="value"></param>
        /// <param name="includeLength">Indicates whether the 4 byte length field should be included</param>
        /// <returns></returns>
        public static byte[] Encode(BigInteger value,bool includeLength=true)
        {
            if(value.Equals(BigInteger.Zero))
            {
                if(!includeLength)
                { return new byte[0]; }
                return new byte[] { 0x00,0x00,0x00,0x00 };
            }

            bool isNegative=value.CompareTo(BigInteger.Zero)<0;
            if(isNegative)
            { value=value.Negate(); }

            byte[] array=value.ToByteArray();
            int length=array.Length;
            if((array[0] & 0x80)==0x80)
            { length++; }

            if(includeLength)
            {
                byte[] result=new byte[length+4];
                Array.Copy(array,0,result,length-array.Length+3,array.Length);
                ((uint)length).ToByteArrayBe(result);

                if(isNegative)
                { result[4]|=0x80; }
                return result;
            }
            else
            {
                byte[] result;
                if(length!=array.Length)
                {
                    result=new byte[length];
                    Array.Copy(array,0,result,1,array.Length);
                }
                else
                { result=array; }

                if(isNegative)
                { result[0]|=0x80; }

                return result;
            }
        }
开发者ID:knocte,项目名称:BitcoinDotNet,代码行数:52,代码来源:MPIHelper.cs

示例7: DerEnumerated

 public DerEnumerated(
     BigInteger   value)
 {
     bytes = value.ToByteArray();
 }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:5,代码来源:DerEnumerated.cs

示例8: KeyPair

 public KeyPair(BigInteger priv, BigInteger pub)
 {
     _priv = priv;
     _pub = pub;
     _pubBytes = pub.ToByteArray();
 }
开发者ID:kueiwa,项目名称:ripple-cs,代码行数:6,代码来源:KeyPair.cs

示例9: SetKeyByString

 public void SetKeyByString(string priv, string pub)
 {
     m_Priv = new BigInteger(1,HexString2Bytes(priv));
     m_Pub = HexString2Bytes(pub);
     m_Address = ConvertPubKeyToAddress(m_Pub);
     m_PubKeyString = bytesToHexString(m_Pub);
     m_PrivKeyString = bytesToHexString(m_Priv.ToByteArray());
 }
开发者ID:brightersky,项目名称:MicroCash-Thin-Client,代码行数:8,代码来源:eckey.cs

示例10: SetKeyByString

 public void SetKeyByString(string priv, string pub)
 {
     PrivateKey = new BigInteger(1,HexString2Bytes(priv));
     PublicKeyBytes = HexString2Bytes(pub);
     AddressBytes = ConvertPubKeyToAddress(PublicKeyBytes);
     PublicKeyString = bytesToHexString(PublicKeyBytes);
     PrivateKeyString = bytesToHexString(PrivateKey.ToByteArray());
 }
开发者ID:n4v,项目名称:MicroCash-Thin-Client,代码行数:8,代码来源:eckey.cs

示例11: WriteBigInteger

        // -- BigInt & UBigInt

        public void WriteBigInteger(BigInteger value)
        {
            var bytes = value.ToByteArray();
            Array.Reverse(bytes);

            WriteByteArray(bytes);
        }
开发者ID:beppe9000,项目名称:MineLib.Network,代码行数:9,代码来源:MinecraftStream.cs

示例12: BigIntegerToByteArray

 private static byte[] BigIntegerToByteArray(BigInteger input, int length)
 {
     byte[] result = new byte[length];
     byte[] inputBytes = input.ToByteArray();
     Array.Reverse(inputBytes);
     Buffer.BlockCopy(inputBytes, 0, result, 0, System.Math.Min(inputBytes.Length, result.Length));
     Array.Reverse(result);
     return result;
 }
开发者ID:cwschroeder,项目名称:MeterTestComService,代码行数:9,代码来源:SignatureAlgorithmECDSA.cs

示例13: DSAKeyParams

        public DSAKeyParams(BigInteger p, BigInteger q, BigInteger g, BigInteger x)
        {
            if (p == null)
                throw new ArgumentException("DSAKeyHexStrings:DSA key parameter P cannot be null");

            if (q == null)
                throw new ArgumentException("DSAKeyHexStrings:DSA key parameter Q cannot be null");

            if (g == null)
                throw new ArgumentException("DSAKeyHexStrings:DSA key parameter G cannot be null");

            if (x == null)
                throw new ArgumentException("DSAKeyHexStrings:DSA key parameter X cannot be null");

            _p = p;
            _q = q;
            _g = g;
            _x = x;

            _p_hex = OTR.Utilities.Utility.ByteToHex(p.ToByteArray());

            _q_hex = OTR.Utilities.Utility.ByteToHex(q.ToByteArray());

            _g_hex = OTR.Utilities.Utility.ByteToHex(g.ToByteArray());

            _x_hex = OTR.Utilities.Utility.ByteToHex(x.ToByteArray());
        }
开发者ID:zamud,项目名称:OTRLib,代码行数:27,代码来源:OTRObjectscs.cs

示例14: int2octets

 private byte[] int2octets(BigInteger v)
 {
     byte[] @out = v.ToByteArray();
     if(@out.Length < rolen)
     {
         byte[] out2 = new byte[rolen];
         Array.Copy(@out, 0,
                 out2, rolen - @out.Length,
                 @out.Length);
         return out2;
     }
     else if(@out.Length > rolen)
     {
         byte[] out2 = new byte[rolen];
         Array.Copy(@out, @out.Length - rolen,
                 out2, 0, rolen);
         return out2;
     }
     else
     {
         return @out;
     }
 }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:23,代码来源:DeterministicECDSA.cs

示例15: AddBigIntBlob

 /// <summary>
 /// Adds BigInteger to builder prefixed with size
 /// </summary>
 /// <param name="bigInt"></param>
 public void AddBigIntBlob(BigInteger aBigInt)
 {
     byte[] bytes = aBigInt.ToByteArray();
       AddBlob(bytes);
 }
开发者ID:dlech,项目名称:SshAgentLib,代码行数:9,代码来源:BlobBuilder.cs


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