How to convert Bouncy Castle SCrypt Byte array to String format or HexString format?

1.8k views Asked by At

Bouncy Castle SCrypt Java API.

byte[] sCryptHash = SCrypt.generate(plaintextPassword.getBytes(), salt.getBytes(), 16384, 8, 1, 1024);
String str = sCryptHash.toString();

The above generate method gives byte[ ] format, I need to store it in database as a String, toString() does not help in comparing, I expect some characters issue in toString().

Is there a way to convert it to String Safely ?

Any other alternative to Bouncy Castle ?

1

There are 1 answers

0
Jens On BEST ANSWER

If you need a hex representation you can use org.bouncycastle.util.encoders.Hex.toHexString(sCryptHash)