X9IntegerConverter.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9
  7. {
  8. public abstract class X9IntegerConverter
  9. {
  10. public static int GetByteLength(ECFieldElement fe)
  11. {
  12. return (fe.FieldSize + 7) / 8;
  13. }
  14. public static int GetByteLength(ECCurve c)
  15. {
  16. return (c.FieldSize + 7) / 8;
  17. }
  18. public static byte[] IntegerToBytes(BigInteger s, int qLength)
  19. {
  20. byte[] bytes = s.ToByteArrayUnsigned();
  21. if (qLength < bytes.Length)
  22. {
  23. byte[] tmp = new byte[qLength];
  24. Array.Copy(bytes, bytes.Length - tmp.Length, tmp, 0, tmp.Length);
  25. return tmp;
  26. }
  27. else if (qLength > bytes.Length)
  28. {
  29. byte[] tmp = new byte[qLength];
  30. Array.Copy(bytes, 0, tmp, tmp.Length - bytes.Length, bytes.Length);
  31. return tmp;
  32. }
  33. return bytes;
  34. }
  35. }
  36. }
  37. #pragma warning restore
  38. #endif