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


C# BigInteger.GetBytes方法代码示例

本文整理汇总了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));
         }
     }
 }
开发者ID:kingscl,项目名称:Dukpt.NET,代码行数:19,代码来源:Dukpt.cs

示例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));
         }
     }
 }
开发者ID:wesee,项目名称:Dukpt.NET,代码行数:20,代码来源:Dukpt.cs

示例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
 }
开发者ID:andy012345,项目名称:WoWServer,代码行数:8,代码来源:PacketWriter.cs


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