aerogear-crypto 0.1.2

org.jboss.aerogear.crypto.encoders
Class Hex

java.lang.Object
  extended by org.jboss.aerogear.crypto.encoders.Hex
All Implemented Interfaces:
Encoder

public class Hex
extends Object
implements Encoder

Converts hexadecimal Strings.

This class is thread-safe.

This class contains code from the Apache Common-Codec project


Field Summary
private static char[] DIGITS_LOWER
          Used to build output as Hex
private static char[] DIGITS_UPPER
          Used to build output as Hex
 
Fields inherited from interface org.jboss.aerogear.crypto.encoders.Encoder
BASE64, CHARSET, HEX, RAW
 
Constructor Summary
Hex()
           
 
Method Summary
 byte[] decode(String value)
          Decode a provided string to bytes
private static byte[] decodeHex(char[] data)
          Converts an array of characters representing hexadecimal values into an array of bytes of those same values.
 String encode(byte[] data)
          Converts an array of bytes into a String representing the hexadecimal values of each byte in order.
private static char[] encodeHex(byte[] data)
          Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.
private static char[] encodeHex(byte[] data, boolean toLowerCase)
          Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.
private static char[] encodeHex(byte[] data, char[] toDigits)
          Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.
private static int toDigit(char ch, int index)
          Converts a hexadecimal character to an integer.
 String toString()
          Returns a string representation of the object, which includes the charset name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIGITS_LOWER

private static final char[] DIGITS_LOWER
Used to build output as Hex


DIGITS_UPPER

private static final char[] DIGITS_UPPER
Used to build output as Hex

Constructor Detail

Hex

public Hex()
Method Detail

decodeHex

private static byte[] decodeHex(char[] data)
Converts an array of characters representing hexadecimal values into an array of bytes of those same values. The returned array will be half the length of the passed array, as it takes two characters to represent any given byte. An exception is thrown if the passed char array has an odd number of elements.

Parameters:
data - An array of characters containing hexadecimal digits
Returns:
A byte array containing binary data decoded from the supplied char array.

decode

public byte[] decode(String value)
Description copied from interface: Encoder
Decode a provided string to bytes

Specified by:
decode in interface Encoder
Parameters:
value - to be decoded
Returns:
byte array with decoded data

encodeHex

private static char[] encodeHex(byte[] data)
Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. The returned array will be double the length of the passed array, as it takes two characters to represent any given byte.

Parameters:
data - a byte[] to convert to Hex characters
Returns:
A char[] containing hexadecimal characters

encodeHex

private static char[] encodeHex(byte[] data,
                                boolean toLowerCase)
Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. The returned array will be double the length of the passed array, as it takes two characters to represent any given byte.

Parameters:
data - a byte[] to convert to Hex characters
toLowerCase - true converts to lowercase, false to uppercase
Returns:
A char[] containing hexadecimal characters
Since:
1.4

encodeHex

private static char[] encodeHex(byte[] data,
                                char[] toDigits)
Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. The returned array will be double the length of the passed array, as it takes two characters to represent any given byte.

Parameters:
data - a byte[] to convert to Hex characters
toDigits - the output alphabet
Returns:
A char[] containing hexadecimal characters
Since:
1.4

encode

public String encode(byte[] data)
Converts an array of bytes into a String representing the hexadecimal values of each byte in order. The returned String will be double the length of the passed array, as it takes two characters to represent any given byte.

Specified by:
encode in interface Encoder
Parameters:
data - a byte[] to convert to Hex characters
Returns:
A String containing hexadecimal characters
Since:
1.4

toDigit

private static int toDigit(char ch,
                           int index)
Converts a hexadecimal character to an integer.

Parameters:
ch - A character to convert to an integer digit
index - The index of the character in the source
Returns:
An integer

toString

public String toString()
Returns a string representation of the object, which includes the charset name.

Overrides:
toString in class Object
Returns:
a string representation of the object.

aerogear-crypto 0.1.2

Copyright © 2013 JBoss by Red Hat. All Rights Reserved.