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


C# BigInteger.ToByteArrayUnsigned方法代码示例

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


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

示例1: ECPrivateKeyStructure

        public ECPrivateKeyStructure(
            BigInteger key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            this.seq = new DerSequence(
                new DerInteger(1),
                new DerOctetString(key.ToByteArrayUnsigned()));
        }
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:10,代码来源:ECPrivateKeyStructure.cs

示例2: AsUnsignedByteArray

		/**
         * Return the passed in value as an unsigned byte array of specified length, zero-extended as necessary.
         *
         * @param length desired length of result array.
         * @param n value to be converted.
         * @return a byte array of specified length, with leading zeroes as necessary given the size of n.
         */
		public static byte[] AsUnsignedByteArray(int length, BigInteger n)
		{
			byte[] bytes = n.ToByteArrayUnsigned();

			if(bytes.Length > length)
				throw new ArgumentException("standard length exceeded", "n");

			if(bytes.Length == length)
				return bytes;

			byte[] tmp = new byte[length];
			Array.Copy(bytes, 0, tmp, tmp.Length - bytes.Length, bytes.Length);
			return tmp;
		}
开发者ID:Nethereum,项目名称:Nethereum,代码行数:21,代码来源:BigIntegers.cs

示例3: IntegerToBytes

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

            if (qLength < bytes.Length)
            {
                byte[] tmp = new byte[qLength];
                Array.Copy(bytes, bytes.Length - tmp.Length, tmp, 0, tmp.Length);
                return tmp;
            }
            else 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:woutersmit,项目名称:NBitcoin,代码行数:19,代码来源:X9IntegerConverter.cs

示例4: GetKey

		public override Key GetKey(string password)
		{
			var encrypted = PartialEncrypted.ToArray();
			//Derive passfactor using scrypt with ownerentropy and the user's passphrase and use it to recompute passpoint
			byte[] passfactor = CalculatePassFactor(password, LotSequence, OwnerEntropy);
			var passpoint = CalculatePassPoint(passfactor);

			var derived = SCrypt.BitcoinComputeDerivedKey2(passpoint, this.AddressHash.Concat(this.OwnerEntropy).ToArray());

			//Decrypt encryptedpart1 to yield the remainder of seedb.
			var seedb = DecryptSeed(encrypted, derived);
			var factorb = Hashes.Hash256(seedb).ToBytes();

			var curve = ECKey.CreateCurve();

			//Multiply passfactor by factorb mod N to yield the private key associated with generatedaddress.
			var keyNum = new BigInteger(1, passfactor).Multiply(new BigInteger(1, factorb)).Mod(curve.N);
			var keyBytes = keyNum.ToByteArrayUnsigned();
			if(keyBytes.Length < 32)
				keyBytes = new byte[32 - keyBytes.Length].Concat(keyBytes).ToArray();

			var key = new Key(keyBytes, fCompressedIn: IsCompressed);

			var generatedaddress = key.PubKey.GetAddress(Network);
			var addresshash = HashAddress(generatedaddress);

			if(!Utils.ArrayEqual(addresshash, AddressHash))
				throw new SecurityException("Invalid password (or invalid Network)");

			return key;
		}
开发者ID:xcrash,项目名称:NBitcoin,代码行数:31,代码来源:BitcoinEncryptedSecret.cs

示例5: ConvertOutput

		public byte[] ConvertOutput(
			BigInteger result)
		{
			byte[] output = result.ToByteArrayUnsigned();

			if (forEncryption)
			{
				int outSize = GetOutputBlockSize();

				// TODO To avoid this, create version of BigInteger.ToByteArray that
				// writes to an existing array
				if (output.Length < outSize) // have ended up with less bytes than normal, lengthen
				{
					byte[] tmp = new byte[outSize];
					output.CopyTo(tmp, tmp.Length - output.Length);
					output = tmp;
				}
			}

			return output;
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:21,代码来源:RSACoreEngine.cs

示例6: ConvertRSAParametersField

        // TODO Move functionality to more general class
		private static byte[] ConvertRSAParametersField(BigInteger n, int size)
		{
			byte[] bs = n.ToByteArrayUnsigned();

			if (bs.Length == size)
				return bs;

			if (bs.Length > size)
				throw new ArgumentException("Specified size too small", "size");

			byte[] padded = new byte[size];
			Array.Copy(bs, 0, padded, size - bs.Length, bs.Length);
			return padded;
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:15,代码来源:DotNetUtilities.cs


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