2
votes

I need to generate a hash function in CN1. I added the BouncyCastle library, but I don't know how to use it. After searching a lot, I found some examples and came up with this:

@Override
protected void onMain_ButtonSHA1Action(Component c, ActionEvent event) {
    String data = "XXXXXXXXXXXXX";
    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);

        labelX.setText(hash.toString());

    } catch (Exception ex) {
    }

}

The result is not working. I know, because I am checking the outcome here: http://www.sha1-online.com/ and it is not the same.

1

1 Answers

2
votes

You are calling toString on a byte[] use new String(hash, "UTF-8").