Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

cryptix.openpgp.util
Class PGPBase64  view PGPBase64 download PGPBase64.java

java.lang.Object
  extended bycryptix.openpgp.util.PGPBase64

public class PGPBase64
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

Version:
$Revision: 1.2 $

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.
private static int LINEBREAK_LENGTH
          This is the maximum number of input bytes represented on each line (not the number of output characters).
 
Constructor Summary
private PGPBase64()
          Constructor is private because this class only has static methods.
 
Method Summary
static byte[] decode(byte[] data)
          Decodes a byte array containing base64-encoded ASCII.
private static int decode(byte[] ret, int ret_off, byte a, byte b, byte c, byte d)
          Given a block of 4 encoded bytes { a, b, c, d }, this method decodes up to 3 bytes of output, and stores them starting at ret[ret_offset].
static byte[] decode(java.lang.String msg)
          Decodes a base64-encoded String.
static java.lang.String encode(byte[] data)
          Encodes data as a String using base64 encoding.
static 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

LINEBREAK_LENGTH

private static final int LINEBREAK_LENGTH
This is the maximum number of input bytes represented on each line (not the number of output characters).

See Also:
Constant Field Values

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

PGPBase64

private PGPBase64()
Constructor is private because this class only has static methods.

Method Detail

encode

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


encodeAsByteArray

public static 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).

Since:
Cryptix 2.2.2

decode

public static 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.


decode

public static 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.


decode

private static int decode(byte[] ret,
                          int ret_off,
                          byte a,
                          byte b,
                          byte c,
                          byte d)
Given a block of 4 encoded bytes { a, b, c, d }, this method decodes up to 3 bytes of output, and stores them starting at ret[ret_offset].