/* * @(#)Base64.java * * Author: Neale Rudd (MetaWerx) * Family: General purpose tool * Type: Command line java application * Purpose: Convert text to/from Base64 encoding * JarFile: n/a * * Copyright (c) 1998-2005, Metawerx Pty Ltd. All Rights Reserved. * PO Box 1114, Huntingdale, VIC, 3166, AUSTRALIA * All rights reserved. * http://www.metawerx.net * * This software is the confidential and proprietary information of Metawerx * ("Confidential Information"). You shall not disclose such Confidential * Information and shall use it only in accordance with the terms of the * license agreement you entered into with Metawerx. * * METAWERX MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE OR THE SOURCE CODE, EITHER EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR * A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. METAWERX SHALL NOT BE LIABLE * FOR ANY DAMAGES SUFFERED BY ANY PARTY AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE AND DOCUMENTATION OR ITS DERIVATIVES * * Synopsis * ===================================================================================== * Command line utility for encoding/decoding Base64 strings. * * History * ===================================================================================== * 01/06/2001 17:26 Neale Rudd * Created * */ import java.io.IOException; public class Base64 { public static void main(String s[]) { if(s.length < 1) { System.err.println("Please specify a string to encode, or a string to decode with the -d parameter"); System.err.println("eg: java Base64 neale"); System.err.println("eg: java Base64 sdg7G -d"); System.exit(1); } if(s.length == 1) { // Encode String => Base64 sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder(); String dec = null; System.out.println("Encoded string "+s[0]+" is: " + encoder.encodeBuffer(s[0].getBytes())); } else { // Decode Base 64 => String sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder(); String dec = null; try { System.out.println("Decoded string of "+s[0]+" is: " + new String(decoder.decodeBuffer(s[0]))); } catch (IOException e) { System.out.println("Error occurred: "+e); } } } }