Android - Decodebase64 Crashes App
I have to encrypt a String but the app doesn't reach the encrypt method, it crashes on load. I'm using Apache Commons Codec library. private EditText txtPass = (EditText)findViewB
Solution 1:
Try this:
// decode data from base 64privatestaticbyte[] decodeBase64(String dataToDecode)
{
byte[] dataDecoded = Base64.decode(dataToDecode, Base64.DEFAULT);
return dataDecoded;
}
//enconde data in base 64privatestaticbyte[] encodeBase64(byte[] dataToEncode)
{
byte[] dataEncoded = Base64.encode(dataToEncode, Base64.DEFAULT);
return dataEncoded;
}
Solution 2:
Simply create an object of Base64 and use it to encode or decode in Android, when using org.apache.commons.codec.binary.Base64 library
To Encode
Base64 ed=new Base64();
String encoded=new String(ed.encode("Hello".getBytes()));
Replace "Hello" with the text to be encoded in String Format.
To Decode
Base64 ed=new Base64();
String decoded=new String(ed.decode(encoded.getBytes()));
Here encoded is the String variable to be decoded
Solution 3:
you are giving a string as an input you should give key.getBytes() to the decode methos
Post a Comment for "Android - Decodebase64 Crashes App"