public class ConvertUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static byte[] |
fromHexToBytes(java.lang.String hexString)
Converts an hex back to an byte array.
|
static java.lang.String |
fromHexToString(java.lang.String hexString)
Converts hex string to a plain string
|
static java.lang.String |
fromStringToHex(java.lang.String plainText)
Converts plain string to an hex string
|
static byte[] |
getBytes(java.lang.String hexString)
Converts a hex string to a byte array.
|
static boolean |
isHexString(java.lang.String input)
Determines whether or not a string is a hex string.
|
static java.lang.String |
padHex(java.lang.String hex,
int hexStringSize)
Adds 0 to the left of the hex to convert the hex to the right size.
|
static java.lang.String |
reverseHexString(java.lang.String hex)
Reversed conversion of an hex string to a new hex
|
static java.lang.String |
toHex(byte[] bytes)
Converts a byte array to a hex string.
|
static java.lang.String |
toSize16Hex(java.math.BigInteger number)
Converts a number to hex padding zeros up to size 16.
|
static java.lang.String |
toString(java.math.BigInteger number)
Converts a BigInteger to an string.
|
static java.math.BigInteger |
toUnsignedBigInteger(java.math.BigInteger value)
It converts a signed BigInteger into an unsigned BigInteger.
|
static java.math.BigInteger |
toUnsignedBigInteger(long value)
It converts a signed long into an unsigned BigInteger.
|
static void |
validateIsHexString(java.lang.String input)
Validates that an input is a valid hex .
|
static void |
validateIsHexString(java.lang.String input,
java.lang.Integer size)
Validates that an input is a valid hex and of the given size.
|
static void |
validateNotNegative(java.math.BigInteger number)
Validates that the provided number is not negative
|
static void |
validateNotNegative(long number)
Validates that the provided number is not negative
|
static byte[] |
xor(byte[] b1,
byte[] b2)
It xors two bytes array into one.
|
static org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.Integer> |
xorValues(java.lang.String originalValue,
java.lang.String newValue)
A method that XORs to values.
|
public static byte[] getBytes(java.lang.String hexString)
hexString
- The input hex string.public static java.lang.String toHex(byte[] bytes)
bytes
- The input byte array.public static java.lang.String padHex(java.lang.String hex, int hexStringSize)
hex
- the hexhexStringSize
- the expected hex string sizepublic static byte[] fromHexToBytes(java.lang.String hexString)
hexString
- the hex string inputpublic static org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.Integer> xorValues(java.lang.String originalValue, java.lang.String newValue)
originalValue
- the original valuenewValue
- the new valuepublic static java.lang.String fromHexToString(java.lang.String hexString)
hexString
- The input string.public static java.lang.String fromStringToHex(java.lang.String plainText)
plainText
- The plain input string.public static java.lang.String toSize16Hex(java.math.BigInteger number)
number
- The input number.public static void validateNotNegative(java.math.BigInteger number)
number
- the number to be tested.java.lang.IllegalArgumentException
- if the number is null or negativepublic static void validateNotNegative(long number)
number
- the number to be tested.java.lang.IllegalArgumentException
- if the number is negativepublic static java.lang.String toString(java.math.BigInteger number)
number
- the inputpublic static java.math.BigInteger toUnsignedBigInteger(long value)
value
- the value, positive or negative.BigInteger
.public static java.math.BigInteger toUnsignedBigInteger(java.math.BigInteger value)
value
- the value, positive or negative.BigInteger
.public static boolean isHexString(java.lang.String input)
input
- The string to test.public static void validateIsHexString(java.lang.String input)
IllegalArgumentException
input
- the string inputjava.lang.IllegalArgumentException
- if the input is null or not an hex.public static void validateIsHexString(java.lang.String input, java.lang.Integer size)
IllegalArgumentException
input
- the string inputsize
- the expected hex size.java.lang.IllegalArgumentException
- if the input is null, not an hex or it has an invalid size.public static java.lang.String reverseHexString(java.lang.String hex)
hex
- the hex string.public static byte[] xor(byte[] b1, byte[] b2)
b1
- the first byte arrayb2
- the second byte array