/** * Creates a new instance of <tt>RFC2307OpenLDAPSSHAPasswordEncryptor</tt> * */ public RFC2307SMD5PasswordEncryptor() { super(); this.digester = new StandardStringDigester(); this.digester.setAlgorithm("MD5"); this.digester.setIterations(1); this.digester.setSaltSizeBytes(8); this.digester.setPrefix("{SMD5}"); this.digester.setInvertPositionOfSaltInMessageBeforeDigesting(true); this.digester.setInvertPositionOfPlainSaltInEncryptionResults(true); this.digester.setUseLenientSaltSizeCheck(true); }
/** * Encrypts (digests) a password. * * @param password the password to be encrypted. * @return the resulting digest. * @see StandardStringDigester#digest(String) */ public String encryptPassword(final String password) { return this.digester.digest(password); }
@Override public boolean validateDigest(String message, String digest) { return digest == null ? false : this.digester.matches(message, digest); } }
/** * Creates a new instance of <tt>StrongPasswordEncryptor</tt> * */ public StrongPasswordEncryptor() { super(); this.digester = new StandardStringDigester(); this.digester.setAlgorithm("SHA-256"); this.digester.setIterations(100000); this.digester.setSaltSizeBytes(16); this.digester.initialize(); }
/** * Creates a new instance of <tt>RFC2307MD5PasswordEncryptor</tt> * */ public RFC2307MD5PasswordEncryptor() { super(); this.digester = new StandardStringDigester(); this.digester.setAlgorithm("MD5"); this.digester.setIterations(1); this.digester.setSaltSizeBytes(0); this.digester.setPrefix("{MD5}"); }
/** * Creates a new instance of <tt>BasicPasswordEncryptor</tt> * */ public BasicPasswordEncryptor() { super(); this.digester = new StandardStringDigester(); this.digester.initialize(); }
private StandardStringDigester getDigester(final CipherAlgorithm cipherAlgorithm) { StandardStringDigester digester = new StandardStringDigester(); if (cipherAlgorithm.getAlgorithm().startsWith("S-")) { // Salted ... digester.setAlgorithm(cipherAlgorithm.getAlgorithm().replaceFirst("S\\-", "")); digester.setIterations(SALT_ITERATIONS); digester.setSaltSizeBytes(SALT_SIZE_BYTES); digester.setInvertPositionOfPlainSaltInEncryptionResults(IPOPSIER); digester.setInvertPositionOfSaltInMessageBeforeDigesting(IPOSIMBD); digester.setUseLenientSaltSizeCheck(ULSSC); } else { // Not salted ... digester.setAlgorithm(cipherAlgorithm.getAlgorithm()); digester.setIterations(1); digester.setSaltSizeBytes(0); } digester.setStringOutputType(CommonUtils.STRING_OUTPUT_TYPE_HEXADECIMAL); return digester; } }
StandardStringDigester cloneDigester() { // Check initialization if (!isInitialized()) { initialize(); } final StandardStringDigester cloned = new StandardStringDigester(this.byteDigester.cloneDigester()); cloned.setPrefix(this.prefix); cloned.setSuffix(this.suffix); if (CommonUtils.isNotEmpty(this.stringOutputType)) { cloned.setStringOutputType(this.stringOutputType); } cloned.setUnicodeNormalizationIgnored(this.unicodeNormalizationIgnored); return cloned; }
/** * Creates a new instance of <tt>ConfigurablePasswordEncryptor</tt> * */ public ConfigurablePasswordEncryptor() { super(); this.digester = new StandardStringDigester(); }
if (!isInitialized()) { initialize();
/** * <p> * Sets the the form in which String output * will be encoded. Available encoding types are: * </p> * <ul> * <li><tt><b>base64</b></tt> (default)</li> * <li><tt><b>hexadecimal</b></tt></li> * </ul> * * @param stringOutputType the string output type. */ public void setStringOutputType(final String stringOutputType) { this.digester.setStringOutputType(stringOutputType); }
/** * Lets the user specify if he/she wants a plain digest used as an * encryption mechanism (no salt or iterations, as with * {@link java.security.MessageDigest}), or rather use the * jasypt's usual stronger mechanism for password encryption (based * on the use of a salt and the iteration of the hash function). * * @param plainDigest true for using plain digests, false for the strong * salt and iteration count based mechanism. */ public void setPlainDigest(final boolean plainDigest) { if (plainDigest) { this.digester.setIterations(1); this.digester.setSaltSizeBytes(0); } else { this.digester.setIterations(StandardByteDigester.DEFAULT_ITERATIONS); this.digester.setSaltSizeBytes(StandardByteDigester.DEFAULT_SALT_SIZE_BYTES); } }
/** * <p> * Sets the size (in bytes) of the salt to be used. * </p> * <p> * Default is 8. * </p> * * @param saltSizeBytes the salt size in bytes */ public void setSaltSizeBytes(final int saltSizeBytes) { this.digester.setSaltSizeBytes(saltSizeBytes); }
/** * <p> * Whether the salt bytes are to be appended after the * message ones before performing the digest operation on the whole. The * default behaviour is to insert those bytes before the message bytes, but * setting this configuration item to <tt>true</tt> allows compatibility * with some external systems and specifications (e.g. LDAP {SSHA}). * </p> * <p> * If this parameter is not explicitly set, the default behaviour * (insertion of salt before message) will be applied. * </p> * * @param invertPositionOfSaltInMessageBeforeDigesting * whether salt will be appended after the message before applying * the digest operation on the whole, instead of inserted before it * (which is the default). */ public synchronized void setInvertPositionOfSaltInMessageBeforeDigesting( final boolean invertPositionOfSaltInMessageBeforeDigesting) { this.firstDigester.setInvertPositionOfSaltInMessageBeforeDigesting(invertPositionOfSaltInMessageBeforeDigesting); }
/** * <p> * Whether the plain (not hashed) salt bytes are to * be appended after the digest operation result bytes. The default behaviour is * to insert them before the digest result, but setting this configuration * item to <tt>true</tt> allows compatibility with some external systems * and specifications (e.g. LDAP {SSHA}). * </p> * <p> * If this parameter is not explicitly set, the default behaviour * (insertion of plain salt before digest result) will be applied. * </p> * * @since 1.7 * * @param invertPositionOfPlainSaltInEncryptionResults * whether plain salt will be appended after the digest operation * result instead of inserted before it (which is the * default). */ public synchronized void setInvertPositionOfPlainSaltInEncryptionResults( final boolean invertPositionOfPlainSaltInEncryptionResults) { this.firstDigester.setInvertPositionOfPlainSaltInEncryptionResults(invertPositionOfPlainSaltInEncryptionResults); }
/** * Creates a new instance of <tt>RFC2307SHAPasswordEncryptor</tt> * */ public RFC2307SHAPasswordEncryptor() { super(); this.digester = new StandardStringDigester(); this.digester.setAlgorithm("SHA-1"); this.digester.setIterations(1); this.digester.setSaltSizeBytes(0); this.digester.setPrefix("{SHA}"); }
/** * Creates a new instance of <tt>StrongPasswordEncryptor</tt> * */ public StrongPasswordEncryptor() { super(); this.digester = new StandardStringDigester(); this.digester.setAlgorithm("SHA-256"); this.digester.setIterations(100000); this.digester.setSaltSizeBytes(16); this.digester.initialize(); }
private StandardStringDigester getDigester(final CipherAlgorithm cipherAlgorithm) { StandardStringDigester digester = digesters.get(cipherAlgorithm); if (digester == null) { digester = new StandardStringDigester(); if (cipherAlgorithm.getAlgorithm().startsWith("S-")) { // Salted ... digester.setAlgorithm(cipherAlgorithm.getAlgorithm().replaceFirst("S\\-", "")); digester.setIterations(SALT_ITERATIONS); digester.setSaltSizeBytes(SALT_SIZE_BYTES); digester.setInvertPositionOfPlainSaltInEncryptionResults(IPOPSIER); digester.setInvertPositionOfSaltInMessageBeforeDigesting(IPOSIMBD); digester.setUseLenientSaltSizeCheck(ULSSC); } else { // Not salted ... digester.setAlgorithm(cipherAlgorithm.getAlgorithm()); digester.setIterations(1); digester.setSaltSizeBytes(0); } digester.setStringOutputType(CommonUtils.STRING_OUTPUT_TYPE_HEXADECIMAL); digesters.put(cipherAlgorithm, digester); } return digester; } }
StandardStringDigester cloneDigester() { // Check initialization if (!isInitialized()) { initialize(); } final StandardStringDigester cloned = new StandardStringDigester(this.byteDigester.cloneDigester()); cloned.setPrefix(this.prefix); cloned.setSuffix(this.suffix); if (CommonUtils.isNotEmpty(this.stringOutputType)) { cloned.setStringOutputType(this.stringOutputType); } cloned.setUnicodeNormalizationIgnored(this.unicodeNormalizationIgnored); return cloned; }
/** * Creates a new instance of <tt>BasicPasswordEncryptor</tt> * */ public BasicPasswordEncryptor() { super(); this.digester = new StandardStringDigester(); this.digester.initialize(); }