If you are using Android then you can use android.util.Base64 class.
Encode:
passwd = Base64.encodeToString( passwd.getBytes(), Base64.DEFAULT );
Decode:
passwd = new String( Base64.decode( passwd, Base64.DEFAULT ) );
A simple and fast single line solution.