Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Base64 encoding decoding in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 369
    Comment on it

    For encoding and decoding we have Base64 class in android.

    For encoding in String we can use encodeToString (byte[] input, int flags)
    This method Base64-encode the given data and return a newly allocated String with the result.
    Parameters
    input-> the data to encode
    flags-> controls certain features of the encoded output. Passing DEFAULT results in output that adheres to RFC 2045.
    Example:-

    public static String getB64Auth(String key) {    
            String ret = Base64.encodeToString(key.getBytes(), Base64.DEFAULT);
            return ret;
    }
    

    For decoding encoded String we can use decode (String str, int flags)
    This method Decode the Base64-encoded data in input and return the data in a new byte array.
    Parameters
    str-> the input String to decode, which is converted to bytes using the default charset
    flags-> controls certain features of the decoded output. Pass DEFAULT to decode standard Base64.
    Example:-

    public static String getDecodedString(String key) {
            byte[] bytes = Base64.decode(key, Base64.DEFAULT);
            return new String(bytes);
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: