本文整理汇总了C#中Mono.Math.BigInteger.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.GetBytes方法的具体用法?C# BigInteger.GetBytes怎么用?C# BigInteger.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.GetBytes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetE
// myKeyAgree=KeyAgreement.getInstance("DiffieHellman");
/// <exception cref="System.Exception"></exception>
public virtual byte[] GetE()
{
if (e == null)
{
DHParameterSpec dhSkipParamSpec = new DHParameterSpec(p, g);
myKpairGen.Initialize(dhSkipParamSpec);
Sharpen.KeyPair myKpair = myKpairGen.GenerateKeyPair();
myKeyAgree.Init(myKpair.GetPrivate());
// BigInteger x=((javax.crypto.interfaces.DHPrivateKey)(myKpair.getPrivate())).getX();
e = ((DHPublicKey)(myKpair.GetPublic())).GetY();
e_array = e.GetBytes();
}
return e_array;
}
示例2: GetCounterHexValue
public static byte[] GetCounterHexValue(BigInteger counter)
{
byte[] counterBytes = counter.GetBytes();
counterBytes = PppConvert.SwapBits(counterBytes);
int padNeeded = 16 - counterBytes.Length;
List<byte> padedBytes;
if (counterBytes.Length != 16)
{
padedBytes = new List<byte>(16);
padedBytes.AddRange(counterBytes);
padedBytes.AddRange(new byte[padNeeded]);
}
else
{
padedBytes = new List<byte>(counterBytes);
}
return padedBytes.ToArray();
}
示例3: GetK
/// <exception cref="System.Exception"></exception>
public virtual byte[] GetK()
{
if (K == null)
{
KeyFactory myKeyFac = KeyFactory.GetInstance("DH");
DHPublicKeySpec keySpec = new DHPublicKeySpec(f, p, g);
PublicKey yourPubKey = myKeyFac.GeneratePublic(keySpec);
myKeyAgree.DoPhase(yourPubKey, true);
byte[] mySharedSecret = myKeyAgree.GenerateSecret();
K = new BigInteger(mySharedSecret);
K_array = K.GetBytes();
//System.err.println("K.signum(): "+K.signum()+
// " "+Integer.toHexString(mySharedSecret[0]&0xff)+
// " "+Integer.toHexString(K_array[0]&0xff));
K_array = mySharedSecret;
}
return K_array;
}
示例4: BigIntToMpi
public static byte[] BigIntToMpi(BigInteger bint)
{
var ibytes = bint.GetBytes();//.Reverse().ToArray();
var shift = 0;// ibytes[0] == 0 ? 1 : 0;
var length = ibytes.Length - shift;
var bytes = new byte[length + 2];
ushort ulength = Convert.ToUInt16(length * 8);
bytes[0] = (byte)(ulength >> 8);
bytes[1] = (byte)(ulength & 0xff);
Array.Copy(ibytes, shift, bytes, 2, length);
return bytes;
}
示例5: GetPaddedValue
private byte[] GetPaddedValue (BigInteger value, int length)
{
byte[] result = value.GetBytes ();
if (result.Length >= length)
return result;
// left-pad 0x00 value on the result (same integer, correct length)
byte[] padded = new byte[length];
Buffer.BlockCopy (result, 0, padded, (length - result.Length), result.Length);
// temporary result may contain decrypted (plaintext) data, clear it
Array.Clear (result, 0, result.Length);
return padded;
}
示例6: EncodeBigInteger
private static System.Numerics.BigInteger EncodeBigInteger(BigInteger v)
{
var bytes = v.GetBytes();
Array.Reverse(bytes);
if ((bytes[bytes.Length - 1] & 128) != 0)
Array.Resize(ref bytes, bytes.Length + 1);
return new System.Numerics.BigInteger(bytes);
}
示例7: RSAExptmod
//for that it s strange because it s a quite different of DecryptValue and encryptvalue
//but maybe it s the same thanks to math ;)
//so need to do some math to check...
public byte[] RSAExptmod(byte[] PacketIn, eRSAKeyFormat format)
{
BigInteger tmp, tmpa, tmpb;
//todo more check key generate format packet in and out null...
tmp = new BigInteger(PacketIn);
/* are we using the private exponent */
if (format == eRSAKeyFormat.PK_PRIVATE )
{
// m1 = c^dp mod p
tmpa = tmp.ModPow (dp, p);
tmpb = tmp.ModPow (dq, q);
tmp = (tmpa * qP + tmpb*pQ).ModPow (0, n);
}
else
{
tmp = tmp.ModPow (e, n);
}
/* convert it */
return tmp.GetBytes();
}