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 txt
Simply create an object of Base64 and use it to encode or decode in Android, when using org.apache.commons.codec.binary.Base64 library
Base64 ed=new Base64();
String encoded=new String(ed.encode("Hello".getBytes()));
Replace "Hello" with the text to be encoded in String Format.
Base64 ed=new Base64();
String decoded=new String(ed.decode(encoded.getBytes()));
Here encoded is the String variable to be decoded
Try this:
// decode data from base 64
private static byte[] decodeBase64(String dataToDecode)
{
byte[] dataDecoded = Base64.decode(dataToDecode, Base64.DEFAULT);
return dataDecoded;
}
//enconde data in base 64
private static byte[] encodeBase64(byte[] dataToEncode)
{
byte[] dataEncoded = Base64.encode(dataToEncode, Base64.DEFAULT);
return dataEncoded;
}
you are giving a string as an input you should give key.getBytes() to the decode methos