Encode / Decode String in android using base64

by Thursday, November 14, 2013 0 comments
Encode/Decode any string using android base64 by using this setbaseEncode/setbaseDecode respectively. You can use this any of activity or separate class.

      public static String setbaseEncode(Context context,String str){  
           byte[] data = null;  
           try {  
                data = str.getBytes("UTF-8");  
           } catch (UnsupportedEncodingException e) {e.printStackTrace();}  
           String domainCode = Base64.encodeToString(data, Base64.DEFAULT);  
           return domainCode;  
      public static String setbaseDecode(Context context,String str){  
           byte[] data = Base64.decode(str, Base64.DEFAULT);  
           String decodestr = null;  
           try {  
                decodestr = new String(data, "UTF-8");  
           } catch (UnsupportedEncodingException e) {  
           return decodestr;  

karthik nagarajan


Welcome to Android-Action Blog. I’m a normal guy, who is passionate about Mobile Coding. Here I am writing about Android. Happy learning


Post a Comment