I am trying to compile this sample of code in my Android app to have crypt/decrypt feature. I found that code here http://apachejava.blogspot.it/2012/04/androidencryption-made-e
Part of the needed code is missing in the page you link : the author forgot to show his Util
class which obviously contains a toByteArray function
.
Solution 1 : use commons IO
Replace
Util.toByteArray(cis);
by
IOUtils.toByteArray(cis);
IOUtils is a Apache commons IO utility class.
You'll need
import org.apache.commons.io.IOUtils;
Solution 2 : write a toByteArray function
Define this function :
public byte[] toByteArray(InputStream is) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int l;
byte[] data = new byte[1024];
while ((l = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, l);
}
buffer.flush();
return buffer.toByteArray();
}
And replace Util.toByteArray(cis);
by toByteArray(cis);
.