本文整理汇总了C#中System.Numerics.BigInteger.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.GetBytes方法的具体用法?C# BigInteger.GetBytes怎么用?C# BigInteger.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.GetBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public static BigInteger Transform(string name, bool encrypt, BigInteger key, BigInteger message)
{
using (var cipher = SymmetricAlgorithm.Create(name))
{
// Bug - https://github.com/sgbj/Dukpt.NET/issues/5 - Specified key is not a valid size for this algorithm.
// I usually trim the zero-bytes off the front of the array in the GetBytes method,
// but this algorithm expects either 8 or 16 byte keys, so GetBytes will occasionally return 7.
var k = key.GetBytes();
cipher.Key = new byte[Math.Max(0, 8 - k.Length)].Concat(key.GetBytes()).ToArray();
cipher.IV = new byte[8];
cipher.Mode = CipherMode.CBC;
cipher.Padding = PaddingMode.Zeros;
using (var crypto = encrypt ? cipher.CreateEncryptor() : cipher.CreateDecryptor())
{
var data = message.GetBytes();
return BigInt.FromBytes(crypto.TransformFinalBlock(data, 0, data.Length));
}
}
}
示例2: Transform
public static BigInteger Transform(string name, bool encrypt, BigInteger key, BigInteger message)
{
using (var cipher = SymmetricAlgorithm.Create(name))
{
var k = key.GetBytes();
//Credit goes to ichoes (https://github.com/ichoes) for fixing this issue (https://github.com/sgbj/Dukpt.NET/issues/5)
//gets the next multiple of 8
cipher.Key = new byte[Math.Max(0, GetNearestWholeMultiple(k.Length, 8) - k.Length)].Concat(key.GetBytes()).ToArray();
cipher.IV = new byte[8];
cipher.Mode = CipherMode.CBC;
cipher.Padding = PaddingMode.Zeros;
using (var crypto = encrypt ? cipher.CreateEncryptor() : cipher.CreateDecryptor())
{
var data = message.GetBytes();
//Added the GetNearestWholeMultiple here.
data = new byte[Math.Max(0, GetNearestWholeMultiple(data.Length, 8) - data.Length)].Concat(message.GetBytes()).ToArray();
return BigInt.FromBytes(crypto.TransformFinalBlock(data, 0, data.Length));
}
}
}
示例3: WriteBigInt
public void WriteBigInt(BigInteger b, int length)
{
byte[] bytes = b.GetBytes();
int bytes_copy_amount = Math.Min(length, bytes.Length);
Write(bytes, 0, bytes_copy_amount);
for (int i = bytes.Length; i < length; ++i)
Write((byte) 0); //pad
}