Package org.owasp.esapi.codecs
Class Hex
- java.lang.Object
-
- org.owasp.esapi.codecs.Hex
-
public class Hex extends java.lang.ObjectEncode and decode to/from hexadecimal strings to byte arrays.
-
-
Constructor Summary
Constructors Constructor Description Hex()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decode(java.lang.String hexStr)Decode hexadecimal-encoded string and return raw byte array.static java.lang.Stringencode(byte[] b, boolean leading0x)Output byte representation as hexadecimal representation.static byte[]fromHex(java.lang.String hexStr)Decode hexadecimal-encoded string and return raw byte array.static java.lang.StringtoHex(byte[] b, boolean leading0x)Output byte representation as hexadecimal representation.
-
-
-
Method Detail
-
toHex
public static java.lang.String toHex(byte[] b, boolean leading0x)Output byte representation as hexadecimal representation.- Parameters:
b- Bytes to encode to hexadecimal representation.leading0x- If true, return with leading "0x".- Returns:
- Hexadecimal representation of specified bytes.
-
encode
public static java.lang.String encode(byte[] b, boolean leading0x)Output byte representation as hexadecimal representation. Alias fortoHex()method.- Parameters:
b- Bytes to encode to hexadecimal representation.leading0x- If true, return with leading "0x".- Returns:
- Hexadecimal representation of specified bytes.
-
fromHex
public static byte[] fromHex(java.lang.String hexStr)
Decode hexadecimal-encoded string and return raw byte array. Important note: This method preserves leading 0 filled bytes on the conversion process, which is important for cryptographic operations in dealing with things like keys, initialization vectors, etc. For example, the string "0x0000face" is going to return a byte array whose length is 4, not 2.- Parameters:
hexStr- Hexadecimal-encoded string, with or without leading "0x".- Returns:
- The equivalent byte array.
-
decode
public static byte[] decode(java.lang.String hexStr)
Decode hexadecimal-encoded string and return raw byte array. Alias forfromHex()method.- Parameters:
hexStr- Hexadecimal-encoded string, with or without leading "0x".- Returns:
- The equivalent byte array.
-
-