本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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);
}
示例5: DerInteger
public DerInteger(
BigInteger value)
{
if (value == null)
throw new ArgumentNullException("value");
bytes = value.ToByteArray();
}
示例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
}
示例7: Agree
public byte[] Agree()
{
IBasicAgreement iba;
iba = AgreementUtilities.GetBasicAgreement("DH");
iba.Init(_kp.Private);
_agreement = iba.CalculateAgreement(RemotePublicKey);
return _agreement.ToByteArray();
}
示例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));
}
示例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;
}
示例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
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}