-
public class Asn1Utils
-
-
Method Summary
Modifier and Type Method Description static inthexCharToInt(char c)static Array<byte>hexStringToBytes(String s)Converts a hex String to a byte array. static StringbytesToHexString(Array<byte> bytes)Converts a byte array into a String of hexadecimal characters. static intbytesToInt(Array<byte> src, int offset, int length)Converts a series of bytes to an integer. static longbytesToRawLong(Array<byte> src, int offset, int length)Converts a series of bytes to a raw long variable which can be both positive and negative.This method currently only supports 64-bit long variable. static Array<byte>unsignedIntToBytes(int value)Converts an integer to a new byte array with base 256 and the most significant digit first. static Array<byte>signedIntToBytes(int value)Converts an integer to a new byte array with base 256 and the most significant digit first.The first byte's highest bit is used for sign. static intunsignedIntToBytes(int value, Array<byte> dest, int offset)Converts an integer to a series of bytes with base 256 and the most significant digit first. static intsignedIntToBytes(int value, Array<byte> dest, int offset)Converts an integer to a series of bytes with base 256 and the most significant digit first.The first byte's highest bit is used for sign. static intbyteNumForUnsignedInt(int value)Calculates the number of required bytes to represent {@code value}.static intbyteNumForSignedInt(int value)Calculates the number of required bytes to represent {@code value}.static bytecountTrailingZeros(byte b)Counts the number of trailing zero bits of a byte. static StringbyteToHex(byte b)Converts a byte to a hex string. -
-
Method Detail
-
hexCharToInt
static int hexCharToInt(char c)
-
hexStringToBytes
static Array<byte> hexStringToBytes(String s)
Converts a hex String to a byte array.
- Parameters:
s- A string of hexadecimal characters, must be an even number ofchars long
-
bytesToHexString
static String bytesToHexString(Array<byte> bytes)
Converts a byte array into a String of hexadecimal characters.
- Parameters:
bytes- an array of bytes
-
bytesToInt
static int bytesToInt(Array<byte> src, int offset, int length)
Converts a series of bytes to an integer. This method currently only supports positive 32-bitintegers.
- Parameters:
src- The source bytes.offset- The position of the first byte of the data to be converted.length- The length of the data to be converted.
-
bytesToRawLong
static long bytesToRawLong(Array<byte> src, int offset, int length)
Converts a series of bytes to a raw long variable which can be both positive and negative.This method currently only supports 64-bit long variable.
- Parameters:
src- The source bytes.offset- The position of the first byte of the data to be converted.length- The length of the data to be converted.
-
unsignedIntToBytes
static Array<byte> unsignedIntToBytes(int value)
Converts an integer to a new byte array with base 256 and the most significant digit first.
-
signedIntToBytes
static Array<byte> signedIntToBytes(int value)
Converts an integer to a new byte array with base 256 and the most significant digit first.The first byte's highest bit is used for sign. If the most significant digit is larger than127, an extra byte (0) will be prepended before it. This method currently doesn't supportnegative values.
-
unsignedIntToBytes
static int unsignedIntToBytes(int value, Array<byte> dest, int offset)
Converts an integer to a series of bytes with base 256 and the most significant digit first.
- Parameters:
value- The integer to be converted.dest- The destination byte array.offset- The start offset of the byte array.
-
signedIntToBytes
static int signedIntToBytes(int value, Array<byte> dest, int offset)
Converts an integer to a series of bytes with base 256 and the most significant digit first.The first byte's highest bit is used for sign. If the most significant digit is larger than127, an extra byte (0) will be prepended before it. This method currently doesn't supportnegative values.
-
byteNumForUnsignedInt
static int byteNumForUnsignedInt(int value)
Calculates the number of required bytes to represent
{@code value}. The bytes will be base256 with the most significant digit first.
-
byteNumForSignedInt
static int byteNumForSignedInt(int value)
Calculates the number of required bytes to represent
{@code value}. The bytes will be base256 with the most significant digit first. If the most significant digit is larger than 127,an extra byte (0) will be prepended before it. This method currently only supports positiveintegers.
-
countTrailingZeros
static byte countTrailingZeros(byte b)
Counts the number of trailing zero bits of a byte.
-
-
-
-