Search code examples
javaarrayscryptographybouncycastlescrypt

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


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 ?


Solution

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