edu.vt.middleware.crypt.util
Class HexConverter

java.lang.Object
  extended by edu.vt.middleware.crypt.util.AbstractEncodingConverter
      extended by edu.vt.middleware.crypt.util.HexConverter
All Implemented Interfaces:
Converter

public class HexConverter
extends AbstractEncodingConverter

Converts bytes to HEX and vice versa.

Version:
$Revision: 3 $
Author:
Middleware Services

Field Summary
static String DEFAULT_BYTE_DELIMITER
          Default byte delimiter.
 
Constructor Summary
HexConverter()
          Creates a new instance.
HexConverter(boolean delimitBytes)
          Creates a new instance that optionally handled delimited bytes in the string input/output.
 
Method Summary
 String fromBytes(byte[] input, int offset, int length)
          Converts a byte array to a formatted/encoded string.
 String getByteDelimiter()
          Gets the byte delmiter string.
protected  org.bouncycastle.util.encoders.Encoder getEncoder()
          Gets the encoder instance that does the work of byte-char/char-byte encoding.
 void setByteDelimiter(String delim)
          Sets the byte delimiter string.
 byte[] toBytes(String input)
          Converts a formatted/encoded string to raw bytes.
 
Methods inherited from class edu.vt.middleware.crypt.util.AbstractEncodingConverter
fromBytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BYTE_DELIMITER

public static final String DEFAULT_BYTE_DELIMITER
Default byte delimiter.

See Also:
Constant Field Values
Constructor Detail

HexConverter

public HexConverter()
Creates a new instance.


HexConverter

public HexConverter(boolean delimitBytes)
Creates a new instance that optionally handled delimited bytes in the string input/output.

Parameters:
delimitBytes - True to handle delimited input and produce delimited output strings with delimiter character, false otherwise. If enabled, the input/output hexadecimal strings would resemble 1A:2B:3C:4D. Call setByteDelimiter(String) to use a delimiter other than DEFAULT_BYTE_DELIMITER.

Note: Setting delimited output has the side effect of producing uppercase hex characters. This is because several cryptographic utilities produce delimited fingerprints with uppercase hex characters, so delimited output keeps with that convention since it is anticipated to be the common use case for this feature.

Method Detail

getByteDelimiter

public String getByteDelimiter()
Gets the byte delmiter string.

Returns:
Byte delimiter string.

setByteDelimiter

public void setByteDelimiter(String delim)
Sets the byte delimiter string. For example, if the delimiter is ":", then output would resemble 1A:2B:3C:4D.

Parameters:
delim - Byte delimiter string.

fromBytes

public String fromBytes(byte[] input,
                        int offset,
                        int length)
Converts a byte array to a formatted/encoded string.

Specified by:
fromBytes in interface Converter
Overrides:
fromBytes in class AbstractEncodingConverter
Parameters:
input - Input bytes.
offset - Offset into input bytes at which to begin processing.
length - Number of bytes of input data to process.
Returns:
Formatted/encoded string derived from input bytes.

toBytes

public byte[] toBytes(String input)
Converts a formatted/encoded string to raw bytes.

Specified by:
toBytes in interface Converter
Overrides:
toBytes in class AbstractEncodingConverter
Parameters:
input - Formatted/encoded input string.
Returns:
Byte array corresponding to input string.

getEncoder

protected org.bouncycastle.util.encoders.Encoder getEncoder()
Gets the encoder instance that does the work of byte-char/char-byte encoding.

Specified by:
getEncoder in class AbstractEncodingConverter
Returns:
Encoder instance.


Copyright © 2003-2011 Virginia Tech. All Rights Reserved.