/** * The digest algorithm to use Supports the named * <a href="http://java.sun.com/j2se/1.4.2/docs/guide/security/CryptoSpec.html#AppA"> * Message Digest Algorithms</a> in the Java environment. * * @param algorithm */ public MessageDigestPasswordEncoder(String algorithm) { this.digester = new Digester(algorithm, 1); }
private String digest(String salt, CharSequence rawPassword) { String saltedPassword = rawPassword + salt; byte[] digest = this.digester.digest(Utf8.encode(saltedPassword)); String encoded = encode(digest); return salt + encoded; }
/** * Create a new Digester. * @param algorithm the digest algorithm; for example, "SHA-1" or "SHA-256". * @param iterations the number of times to apply the digest algorithm to the input */ public Digester(String algorithm, int iterations) { // eagerly validate the algorithm createDigest(algorithm); this.algorithm = algorithm; setIterations(iterations); }
@Test public void digestIsCorrectFor3Iterations() { Digester digester = new Digester("SHA-1", 3); byte[] result = digester.digest(Utf8.encode("text")); // echo -n text | openssl sha1 -binary | openssl sha1 -binary | openssl sha1 assertThat(new String(Hex.encode(result))).isEqualTo("3cfa28da425eca5b894f0af2b158adf7001e000f"); }
/** * Sets the number of iterations for which the calculated hash value should be * "stretched". If this is greater than one, the initial digest is calculated, the * digest function will be called repeatedly on the result for the additional number * of iterations. * * @param iterations the number of iterations which will be executed on the hashed * password/salt value. Defaults to 1. */ public void setIterations(int iterations) { this.digester.setIterations(iterations); }
public byte[] digest(byte[] value) { MessageDigest messageDigest = createDigest(algorithm); for (int i = 0; i < iterations; i++) { value = messageDigest.digest(value); } return value; }
/** * Sets the number of iterations for which the calculated hash value should be * "stretched". If this is greater than one, the initial digest is calculated, the * digest function will be called repeatedly on the result for the additional number * of iterations. * * @param iterations the number of iterations which will be executed on the hashed * password/salt value. Defaults to 1. */ public void setIterations(int iterations) { this.digester.setIterations(iterations); }
public byte[] digest(byte[] value) { MessageDigest messageDigest = createDigest(algorithm); for (int i = 0; i < iterations; i++) { value = messageDigest.digest(value); } return value; }
/** * The digest algorithm to use Supports the named * <a href="http://java.sun.com/j2se/1.4.2/docs/guide/security/CryptoSpec.html#AppA"> * Message Digest Algorithms</a> in the Java environment. * * @param algorithm */ public MessageDigestPasswordEncoder(String algorithm) { this.digester = new Digester(algorithm, 1); }
private String digest(String salt, CharSequence rawPassword) { String saltedPassword = rawPassword + salt; byte[] digest = this.digester.digest(Utf8.encode(saltedPassword)); String encoded = encode(digest); return salt + encoded; }
/** * Create a new Digester. * @param algorithm the digest algorithm; for example, "SHA-1" or "SHA-256". * @param iterations the number of times to apply the digest algorithm to the input */ public Digester(String algorithm, int iterations) { // eagerly validate the algorithm createDigest(algorithm); this.algorithm = algorithm; setIterations(iterations); }
/** * Sets the number of iterations for which the calculated hash value should be * "stretched". If this is greater than one, the initial digest is calculated, the * digest function will be called repeatedly on the result for the additional number * of iterations. * * @param iterations the number of iterations which will be executed on the hashed * password/salt value. Defaults to 1. */ public void setIterations(int iterations) { this.digester.setIterations(iterations); }
public byte[] digest(byte[] value) { MessageDigest messageDigest = createDigest(algorithm); for (int i = 0; i < iterations; i++) { value = messageDigest.digest(value); } return value; }
private StandardPasswordEncoder(String algorithm, CharSequence secret) { this.digester = new Digester(algorithm, DEFAULT_ITERATIONS); this.secret = Utf8.encode(secret); this.saltGenerator = KeyGenerators.secureRandom(); }
private byte[] digest(CharSequence rawPassword, byte[] salt) { byte[] digest = digester.digest(concatenate(salt, secret, Utf8.encode(rawPassword))); return concatenate(salt, digest); }
/** * Create a new Digester. * @param algorithm the digest algorithm; for example, "SHA-1" or "SHA-256". * @param iterations the number of times to apply the digest algorithm to the input */ public Digester(String algorithm, int iterations) { // eagerly validate the algorithm createDigest(algorithm); this.algorithm = algorithm; setIterations(iterations); }
/** * Sets the number of iterations for which the calculated hash value should be * "stretched". If this is greater than one, the initial digest is calculated, the * digest function will be called repeatedly on the result for the additional number * of iterations. * * @param iterations the number of iterations which will be executed on the hashed * password/salt value. Defaults to 1. */ public void setIterations(int iterations) { this.digester.setIterations(iterations); }
public byte[] digest(byte[] value) { MessageDigest messageDigest = createDigest(algorithm); for (int i = 0; i < iterations; i++) { value = messageDigest.digest(value); } return value; }
private StandardPasswordEncoder(String algorithm, CharSequence secret) { this.digester = new Digester(algorithm, DEFAULT_ITERATIONS); this.secret = Utf8.encode(secret); this.saltGenerator = KeyGenerators.secureRandom(); }
private byte[] digest(CharSequence rawPassword, byte[] salt) { byte[] digest = digester.digest(concatenate(salt, secret, Utf8.encode(rawPassword))); return concatenate(salt, digest); }