Class CodecUtil

java.lang.Object
org.cryptacular.util.CodecUtil

public final class CodecUtil extends Object
Utility class for common encoding conversions.
Author:
Middleware Services
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    b32(byte[] raw)
    Encodes bytes into base 32-encoded string.
    static String
    b32(byte[] raw, int lineLength)
    Encodes bytes into base32-encoded string.
    static byte[]
    b32(CharSequence encoded)
    Decodes a base32-encoded string into raw bytes.
    static String
    b64(byte[] raw)
    Encodes bytes into base 64-encoded string.
    static String
    b64(byte[] raw, int lineLength)
    Encodes bytes into base64-encoded string.
    static byte[]
    b64(CharSequence encoded)
    Decodes a base64-encoded string into raw bytes.
    static byte[]
    decode(Decoder decoder, CharSequence encoded)
    Decodes the given encoded data using the given char-to-byte decoder.
    static String
    encode(Encoder encoder, byte[] raw)
    Encodes raw bytes using the given encoder.
    static String
    hex(byte[] raw)
    Encodes raw bytes to the equivalent hexadecimal encoded string.
    static String
    hex(byte[] raw, boolean delimit)
    Encodes raw bytes to the equivalent hexadecimal encoded string with optional delimiting of output.
    static byte[]
    hex(CharSequence encoded)
    Decodes a hexadecimal encoded string to raw bytes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • hex

      public static String hex(byte[] raw) throws EncodingException
      Encodes raw bytes to the equivalent hexadecimal encoded string.
      Parameters:
      raw - Raw bytes to encode.
      Returns:
      Hexadecimal encoded string.
      Throws:
      EncodingException - on encoding errors.
    • hex

      public static String hex(byte[] raw, boolean delimit) throws EncodingException
      Encodes raw bytes to the equivalent hexadecimal encoded string with optional delimiting of output.
      Parameters:
      raw - Raw bytes to encode.
      delimit - True to delimit every two characters (i.e. every byte) of output with ':' character, false otherwise.
      Returns:
      Hexadecimal encoded string.
      Throws:
      EncodingException - on encoding errors.
    • hex

      public static byte[] hex(CharSequence encoded) throws EncodingException
      Decodes a hexadecimal encoded string to raw bytes.
      Parameters:
      encoded - Hex encoded character data.
      Returns:
      Raw bytes of hex string.
      Throws:
      EncodingException - on decoding errors.
    • b64

      public static String b64(byte[] raw) throws EncodingException
      Encodes bytes into base 64-encoded string.
      Parameters:
      raw - Raw bytes to encode.
      Returns:
      Base64-encoded string.
      Throws:
      EncodingException - on encoding errors.
    • b64

      public static byte[] b64(CharSequence encoded) throws EncodingException
      Decodes a base64-encoded string into raw bytes.
      Parameters:
      encoded - Base64-encoded character data.
      Returns:
      Base64-decoded bytes.
      Throws:
      EncodingException - on decoding errors.
    • b64

      public static String b64(byte[] raw, int lineLength) throws EncodingException
      Encodes bytes into base64-encoded string.
      Parameters:
      raw - Raw bytes to encode.
      lineLength - Length of each base64-encoded line in output.
      Returns:
      Base64-encoded string.
      Throws:
      EncodingException - on encoding errors.
    • b32

      public static String b32(byte[] raw) throws EncodingException
      Encodes bytes into base 32-encoded string.
      Parameters:
      raw - Raw bytes to encode.
      Returns:
      Base32-encoded string.
      Throws:
      EncodingException - on encoding errors.
    • b32

      public static byte[] b32(CharSequence encoded) throws EncodingException
      Decodes a base32-encoded string into raw bytes.
      Parameters:
      encoded - Base32-encoded character data.
      Returns:
      Base64-decoded bytes.
      Throws:
      EncodingException - on decoding errors.
    • b32

      public static String b32(byte[] raw, int lineLength) throws EncodingException
      Encodes bytes into base32-encoded string.
      Parameters:
      raw - Raw bytes to encode.
      lineLength - Length of each base32-encoded line in output.
      Returns:
      Base32-encoded string.
      Throws:
      EncodingException - on encoding errors.
    • encode

      public static String encode(Encoder encoder, byte[] raw) throws EncodingException
      Encodes raw bytes using the given encoder.
      Parameters:
      encoder - Encoder to perform byte-to-char conversion.
      raw - Raw bytes to encode.
      Returns:
      Encoded data as a string.
      Throws:
      EncodingException - on encoding errors.
    • decode

      public static byte[] decode(Decoder decoder, CharSequence encoded) throws EncodingException
      Decodes the given encoded data using the given char-to-byte decoder.
      Parameters:
      decoder - Decoder to perform char-to-byte conversion.
      encoded - Encoded character data.
      Returns:
      Decoded data as raw bytes.
      Throws:
      EncodingException - on decoding errors.