0

I'm in the process of completing a login GUI and have been using BCrypt to encrypt a String password. After reading about deprecation warnings, where the getText() method is not recommended for security reasons, I decided to to use getPassword() instead. However, as you are probably aware, it returns the password as a char[] array. How would I pass a char[] array into BCrypt without compromising security by converting the password into a String, which is accessible in memory?

Here is the BCrypt class: org.mindrot.jbcrypt.BCrypt

Community
  • 1
  • 1
user2318861
  • 133
  • 1
  • 1
  • 6

1 Answers1

0

You can use Password4j like this:

char[] password = passwordField.getPassword();
SecureString secure = new SecureString(password);

Password4j.hash(secure).withBCrypt();
// Clear the SecureString object
secure.clear(); 

You can find more info about SecureStrings here.

Mirianna
  • 910
  • 1
  • 8
  • 18