Class BigIntegerUtils


  • public class BigIntegerUtils
    extends java.lang.Object
    Hexadecimal encoding and decoding utility.

    Obtained from Apache Xerces and Aduna Software code on java2s.com.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.math.BigInteger bigIntegerFromBytes​(byte[] bytes)
      Converts a byte array to a positive BigInteger
      static byte[] bigIntegerToBytes​(java.math.BigInteger bigInteger)
      Converts a BigInteger into a byte array ignoring the sign of the BigInteger, according to RFC2945 specification
      static java.math.BigInteger fromHex​(java.lang.String hex)
      Decodes the specified hex string into a big integer.
      static java.lang.String toHex​(java.math.BigInteger bigint)
      Encodes the specified big integer into a hex string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toHex

        public static java.lang.String toHex​(java.math.BigInteger bigint)
        Encodes the specified big integer into a hex string.
        Parameters:
        bigint - the value to convert to a hexidecimal string
        Returns:
        The resulting hex encoded string or null if the input is undefined.
      • fromHex

        public static java.math.BigInteger fromHex​(java.lang.String hex)
        Decodes the specified hex string into a big integer.
        Parameters:
        hex - The hex encoded string to decode.
        Returns:
        The resulting big integer or null if decoding failed.
      • bigIntegerFromBytes

        public static java.math.BigInteger bigIntegerFromBytes​(byte[] bytes)
        Converts a byte array to a positive BigInteger
        Parameters:
        bytes - byte array in big endian unsigned RFC2945 format
        Returns:
        positive BigInteger containing the data of the supplied byte array
      • bigIntegerToBytes

        public static byte[] bigIntegerToBytes​(java.math.BigInteger bigInteger)
        Converts a BigInteger into a byte array ignoring the sign of the BigInteger, according to RFC2945 specification
        Parameters:
        bigInteger - BigInteger, must not be null, should not be negative
        Returns:
        byte array (leading byte is always != 0), empty array if BigInteger is zero.