net.i2p.data
Class Base64

java.lang.Object
  extended by net.i2p.data.Base64

public class Base64
extends java.lang.Object

Encodes and decodes to and from Base64 notation.

Change Log:

I am placing this code in the Public Domain. Do with it as you will. This software comes with no guarantees or warranties but with plenty of well-wishing instead! Please visit http://iharder.net/xmlizable periodically to check for updates or to contribute improvements.

Modified by jrandom for i2p, using safeEncode / safeDecode to create filesystem and URL safe base64 values (replacing / with ~, and + with -)

Version:
1.3.4
Author:
Robert Harder, rob@iharder.net

Method Summary
static byte[] decode(java.lang.String s)
           
static java.lang.String decodeToString(java.lang.String s)
          Decodes data from Base64 notation and returns it as a string.
static java.lang.String encode(byte[] source)
           
static java.lang.String encode(byte[] source, boolean useStandardAlphabet)
           
static java.lang.String encode(byte[] source, int off, int len)
           
static java.lang.String encode(byte[] source, int off, int len, boolean useStandardAlphabet)
           
static java.lang.String encode(java.lang.String source)
           
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encode

public static java.lang.String encode(java.lang.String source)
Parameters:
source - if null will return ""

encode

public static java.lang.String encode(byte[] source)
Parameters:
source - if null will return ""

encode

public static java.lang.String encode(byte[] source,
                                      int off,
                                      int len)
Parameters:
source - if null will return ""

encode

public static java.lang.String encode(byte[] source,
                                      boolean useStandardAlphabet)
Parameters:
source - if null will return ""
useStandardAlphabet - Warning, must be false for I2P compatibility

encode

public static java.lang.String encode(byte[] source,
                                      int off,
                                      int len,
                                      boolean useStandardAlphabet)
Parameters:
source - if null will return ""
useStandardAlphabet - Warning, must be false for I2P compatibility

decode

public static byte[] decode(java.lang.String s)
Parameters:
s - Base 64 encoded string using the I2P alphabet A-Z, a-z, 0-9, -, ~

main

public static void main(java.lang.String[] args)

decodeToString

public static java.lang.String decodeToString(java.lang.String s)
Decodes data from Base64 notation and returns it as a string. Equivlaent to calling new String( decode( s ) )

Parameters:
s - the strind to decode
Returns:
The data as a string
Throws:
NPE - on error?
Since:
1.4