本文整理汇总了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;
}
示例2: DerInteger
public DerInteger(
BigInteger value)
{
if (value == null)
throw new ArgumentNullException("value");
bytes = value.ToByteArray();
}
示例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();
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例7: DerEnumerated
public DerEnumerated(
BigInteger value)
{
bytes = value.ToByteArray();
}
示例8: KeyPair
public KeyPair(BigInteger priv, BigInteger pub)
{
_priv = priv;
_pub = pub;
_pubBytes = pub.ToByteArray();
}
示例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());
}
示例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());
}
示例11: WriteBigInteger
// -- BigInt & UBigInt
public void WriteBigInteger(BigInteger value)
{
var bytes = value.ToByteArray();
Array.Reverse(bytes);
WriteByteArray(bytes);
}
示例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;
}
示例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());
}
示例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;
}
}
示例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);
}