-1

I am working on AES encryption and decryption in Android and for that, I have used this site and code.

After implementing the java file I am getting the error Can not resolve method Base64.encodeBase64String(byte[]).

I have found possible duplicate but It doesn't work for me.

My target is to get, Encrypted Result: +xsGMAefodr7u/bfTIdqoQ== for String: hello world, Key: password and Bit: 128.

Thanks.

Ronak Thakkar
  • 2,515
  • 6
  • 31
  • 45
  • you have to check which package of `Base64` you are importing. the example code in your link uses `org.apache.commons.codec.binary.Base64` , but the [android.util.Base64](https://developer.android.com/reference/android/util/Base64.html) does not have `encodeBase64String` method – ymonad Jul 21 '17 at 06:38
  • 1
    If you want to use apache commons codec, you have to write `compile 'commons-codec:commons-codec:1.10'` in your gradle setting. [site](https://search.maven.org/#artifactdetails%7Ccommons-codec%7Ccommons-codec%7C1.10%7Cjar) – ymonad Jul 21 '17 at 06:45
  • 1
    "I have found possible duplicate but It doesn't work for me." That's not a very good error description, don't you agree? Note that that's a horrible example of performing AES encryption, maybe you should take a few lessons. Then you can mail the guy that wrote the code fragment his mistakes afterwards. – Maarten Bodewes Jul 21 '17 at 07:17

1 Answers1

3

Use the following:

import android.util.Base64;
String base64 = Base64.encodeToString(byte[], Base64.NO_WRAP);