// Copyright 1996, Marimba Inc. All Rights Reserved.


// Confidential and Proprietary Information of Marimba, Inc.


// @(#)Password.java, 1.1, 12/03/96





package marimba.util;





import sun.misc.*;


import java.io.*;





/**


 * This class is used to encrypt and decrypt passwords, using Base64 encoding.


 *


 * @author	Josh Sirota


 * @version	1.1, 12/03/96


 */


public class Password {


    public static String encode(String orig) {


	StringBufferInputStream in = new StringBufferInputStream(orig);


	ByteArrayOutputStream out = new ByteArrayOutputStream();


	PWEncoder encoder = new PWEncoder();





	try {


	    encoder.encodeBuffer(in, out);


	} catch (IOException e) {


	    System.out.println("IOException in BASE64EncodeBuffer");


	}


	return out.toString();


    }





    public static String decode(String pw) {


	BASE64Decoder decoder = new BASE64Decoder();


	


	if (pw == null || pw.length() == 0) {


	    return new String("");


	}





	byte s[] = null;


	try {


	    s = decoder.decodeBuffer(pw);


	} catch (IOException e) {


	    System.out.println("IOException in BASE64EncodeBuffer");


	}


	if (s != null) {


	    return new String(s, 0);


	} else {


	    return new String("");


	}


    }


}


