Example usage for org.bouncycastle.crypto.generators OpenBSDBCrypt generate

List of usage examples for org.bouncycastle.crypto.generators OpenBSDBCrypt generate

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.generators OpenBSDBCrypt generate.

Prototype

public static String generate(char[] password, byte[] salt, int cost) 

Source Link

Document

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$' using version '2y'.

Usage

From source file:com.acciente.oacc.encryptor.bcrypt.BCryptPasswordEncryptor.java

License:Apache License

@Override
public String encryptPassword(char[] plainPassword) {
    if (plainPassword == null) {
        return null;
    }/*from  www . ja  v a  2  s  . c o  m*/
    final char[] normalizedChars = TextNormalizer.getInstance().normalizeToNfc(plainPassword);

    final String bcryptString = OpenBSDBCrypt.generate(normalizedChars, gensalt(), costFactor /* log rounds */);

    return passwordEncoderDecoder.encode(bcryptString);
}

From source file:org.jivesoftware.openfire.auth.JDBCAuthProvider.java

License:Open Source License

protected String hashPassword(String password, PasswordType type) {
    switch (type) {
    case md5://  w  ww  .ja va2 s  . co  m
        return StringUtils.hash(password, "MD5");
    case sha1:
        return StringUtils.hash(password, "SHA-1");
    case sha256:
        return StringUtils.hash(password, "SHA-256");
    case sha512:
        return StringUtils.hash(password, "SHA-512");
    case bcrypt:
        byte[] salt = new byte[16];
        new SecureRandom().nextBytes(salt);
        int cost = (bcryptCost < 4 || bcryptCost > 31) ? DEFAULT_BCRYPT_COST : bcryptCost;
        return OpenBSDBCrypt.generate(password.toCharArray(), salt, cost);
    case plain:
    default:
        return password;
    }
}

From source file:password.pwm.util.BCrypt.java

License:Open Source License

public static String hashPassword(final String password) {
    final int bcryptRounds = 10;
    final byte[] salt = new byte[16];
    (new SecureRandom()).nextBytes(salt);
    return OpenBSDBCrypt.generate(password.toLowerCase().toCharArray(), salt, bcryptRounds);
}