2
votes

I want to hash data with custom key (getting key from user) using SHA1 Digest algorithm. Currently I am hashing data using SHA1 Digest algorithm but can't put custom key for hash data. Can you please let me know how to resolve it?

My application needs to be supported on all platforms (Android, iOS, Windows) and I don't want to write native code for all platforms separately.

1

1 Answers

1
votes

Taken from this question: generate SHA1 hash function in Codename One

SHA1Digest sha1 = new SHA1Digest();
try {
    byte[] b = data.getBytes("UTF-8");
    sha1.update(b, 0, b.length);
    byte[] hash = new byte[sha1.getDigestSize()];
    sha1.doFinal(hash, 0);
    // do something with "hash"
} catch (Exception ex) {
    Log.e(ex);
}