cryptix.util.mime
Class Base64

java.lang.Object
  extended bycryptix.util.mime.Base64

public class Base64
extends java.lang.Object

This class provides methods for encoding and decoding data in MIME base64 format.

The input to the encode methods is always a byte array. Strictly speaking the output represents a sequence of characters, but since these characters are from a subset of both the Unicode and ASCII character repertoires, it is possible to express the output either as a String or as a byte array.

References:

  1. RFC 2045, Multipurpose Internet Mail Extensions (MIME) Part One, Format of Internet Message Bodies, "Section 6.8 Base64 Content-Transfer-Encoding," http://www.imc.org/rfc2045

Copyright © 1995-1997 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.1.1.1 $

Since:
Cryptix 3.0.2
Author:
Jill Baker, David Hopwood

Field Summary
protected static byte[] dec_table
          A static array that maps ASCII code points to a 6-bit integer, or -1 for an invalid code point.
protected static char[] enc_table
          A static array that maps 6-bit integers to a specific char.
 
Constructor Summary
Base64()
          Creates a Base64 transfer-encoding object.
 
Method Summary
 byte[] decode(byte[] data)
          Decodes a byte array containing base64-encoded ASCII.
 byte[] decode(java.lang.String msg)
          Decodes a base64-encoded String.
 java.lang.String encode(byte[] data)
          Encodes data as a String using base64 encoding.
 byte[] encodeAsByteArray(byte[] data)
          Encodes data as a byte array using base64 encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enc_table

protected static final char[] enc_table
A static array that maps 6-bit integers to a specific char.


dec_table

protected static final byte[] dec_table
A static array that maps ASCII code points to a 6-bit integer, or -1 for an invalid code point.

Constructor Detail

Base64

public Base64()
Creates a Base64 transfer-encoding object.

Method Detail

encode

public java.lang.String encode(byte[] data)
Encodes data as a String using base64 encoding. Line breaks in the output are represented as CR LF.

Returns:
the encoded string.

encodeAsByteArray

public byte[] encodeAsByteArray(byte[] data)
Encodes data as a byte array using base64 encoding. The characters 'A'-'Z', 'a'-'z', '0'-'9', '+', '/', and '=' in the output are mapped to their ASCII code points. Line breaks in the output are represented as CR LF (codes 13 and 10).

Returns:
the encoded byte array.
Since:
Cryptix 2.2.2

decode

public byte[] decode(byte[] data)
Decodes a byte array containing base64-encoded ASCII. Characters with ASCII code points <= 32 (this includes whitespace and newlines) are ignored.

Returns:
the decoded data.
Throws:
java.lang.IllegalArgumentException - if data contains invalid characters, i.e. not codes 0-32, 'A'-'Z', 'a'-'z', '+', '/'. or '=', or is incorrectly padded.

decode

public byte[] decode(java.lang.String msg)
              throws java.lang.IllegalArgumentException
Decodes a base64-encoded String. Characters with ASCII code points <= 32 (this includes whitespace and newlines) are ignored.

Returns:
the decoded data.
Throws:
java.lang.IllegalArgumentException - if data contains invalid characters, i.e. not codes 0-32, 'A'-'Z', 'a'-'z', '+', '/'. or '=', or is incorrectly padded.