Class Sha256HexPasswordEncoder

java.lang.Object
com.codename1.backend.security.crypto.Sha256HexPasswordEncoder
All Implemented Interfaces:
PasswordEncoder

public final class Sha256HexPasswordEncoder extends Object implements PasswordEncoder

The hexadecimal SHA-256 of a value, unsalted and in one round. Registered as {sha256}.

This exists to verify values another system stored this way, so that they can be imported without asking every user for new ones: recovery codes, or tokens that are long and random. A single unsalted digest is far too fast for a password a person chose; never encode those with it.

matches(CharSequence, String) compares in constant time and accepts upper or lower case hexadecimal, and upgradeEncoding(String) is always true.

  • Constructor Details

    • Sha256HexPasswordEncoder

      public Sha256HexPasswordEncoder()
  • Method Details

    • encode

      public String encode(CharSequence rawPassword)
      Description copied from interface: PasswordEncoder
      The password as it should be stored: salted and hashed, so encoding one password twice gives two different results.
      Specified by:
      encode in interface PasswordEncoder
    • matches

      public boolean matches(CharSequence rawPassword, String encodedPassword)
      Description copied from interface: PasswordEncoder
      Whether rawPassword is the password encodedPassword was made from.
      Specified by:
      matches in interface PasswordEncoder
    • upgradeEncoding

      public boolean upgradeEncoding(String encodedPassword)
      Description copied from interface: PasswordEncoder
      Whether encodedPassword should be encoded again for better protection: it was made by an older scheme, or with fewer rounds than this encoder uses now.
      Specified by:
      upgradeEncoding in interface PasswordEncoder