Example usage for org.springframework.security.crypto.bcrypt BCrypt gensalt

List of usage examples for org.springframework.security.crypto.bcrypt BCrypt gensalt

Introduction

In this page you can find the example usage for org.springframework.security.crypto.bcrypt BCrypt gensalt.

Prototype

public static String gensalt() 

Source Link

Document

Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable default for the number of hashing rounds to apply

Usage

From source file:bean.RedSocial.java

/**
 * /*from  w ww .  j  ava  2s.  c o m*/
 * @param _newPassword 
 * @throws java.security.NoSuchAlgorithmException 
 */
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = transactionalBusinessException.CambiarPasswordException.class)
public void cambiarPassword(String _newPassword) throws NoSuchAlgorithmException {
    String hash = BCrypt.hashpw(_newPassword, BCrypt.gensalt());

    usuarioConectado = daoUsuario.obtenerUsuario(username);

    usuarioConectado.setPassword(hash);

    daoUsuario.actualizarUsuario(usuarioConectado);
}

From source file:de.ingrid.admin.controller.GeneralController.java

private void setConfiguration(PlugdescriptionCommandObject pd) {
    Config config = JettyStarter.getInstance().config;

    config.mainPartner = pd.getOrganisationPartnerAbbr();
    config.mainProvider = pd.getOrganisationAbbr();
    config.organisation = pd.getOrganisation();
    config.personTitle = pd.getPersonTitle();
    config.personName = pd.getPersonName();
    config.personSurname = pd.getPersonSureName();
    config.personPhone = pd.getPersonPhone();
    config.personEmail = pd.getPersonMail();
    config.datasourceName = pd.getDataSourceName();
    config.datasourceDescription = pd.getDataSourceDescription();
    config.datatypesOfIndex = pd.getDatatypesOfIndex();
    config.datatypes.clear();//from  www  . ja v  a 2 s. c o m
    if (pd.getDatatypesOfIndex().isEmpty()) {
        config.datatypes.addAll(Arrays.asList(pd.getDataTypes()));
    } else {
        config.datatypes.addAll(Utils.getUnionOfDatatypes(config.datatypesOfIndex));
    }
    config.guiUrl = pd.getIplugAdminGuiUrl();
    config.webappPort = pd.getIplugAdminGuiPort();
    String newPassword = pd.getNewPassword();
    if (newPassword != null && newPassword.trim().length() > 0) {
        String pw_hash = BCrypt.hashpw(newPassword, BCrypt.gensalt());
        config.pdPassword = pw_hash;
        pd.setIplugAdminPassword(pw_hash);
    }

}

From source file:com.github.mrstampy.gameboot.usersession.processor.UserMessageProcessor.java

/**
 * Sets the password hash.//from   w w  w  .  ja  va  2s  .c  o  m
 *
 * @param message
 *          the message
 * @param user
 *          the user
 */
protected void setPasswordHash(UserMessage message, User user) {
    String salt = BCrypt.gensalt();
    user.setPasswordHash(BCrypt.hashpw(message.getNewPassword(), salt));
}

From source file:org.apache.syncope.core.misc.security.Encryptor.java

public String encode(final String value, final CipherAlgorithm cipherAlgorithm)
        throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException,
        InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

    String encodedValue = null;//from  w  w  w .  jav a 2 s  .  c o m

    if (value != null) {
        if (cipherAlgorithm == null || cipherAlgorithm == CipherAlgorithm.AES) {
            final byte[] cleartext = value.getBytes(SyncopeConstants.DEFAULT_CHARSET);

            final Cipher cipher = Cipher.getInstance(CipherAlgorithm.AES.getAlgorithm());
            cipher.init(Cipher.ENCRYPT_MODE, keySpec);

            encodedValue = new String(Base64.encode(cipher.doFinal(cleartext)));
        } else if (cipherAlgorithm == CipherAlgorithm.BCRYPT) {
            encodedValue = BCrypt.hashpw(value, BCrypt.gensalt());
        } else {
            encodedValue = getDigester(cipherAlgorithm).digest(value);
        }
    }

    return encodedValue;
}

From source file:org.apache.syncope.core.spring.security.Encryptor.java

public String encode(final String value, final CipherAlgorithm cipherAlgorithm)
        throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException,
        InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

    String encodedValue = null;//from   ww w.  jav a 2s  .  com

    if (value != null) {
        if (cipherAlgorithm == null || cipherAlgorithm == CipherAlgorithm.AES) {
            final byte[] cleartext = value.getBytes(StandardCharsets.UTF_8);

            final Cipher cipher = Cipher.getInstance(CipherAlgorithm.AES.getAlgorithm());
            cipher.init(Cipher.ENCRYPT_MODE, keySpec);

            encodedValue = new String(Base64.getEncoder().encode(cipher.doFinal(cleartext)));
        } else if (cipherAlgorithm == CipherAlgorithm.BCRYPT) {
            encodedValue = BCrypt.hashpw(value, BCrypt.gensalt());
        } else {
            encodedValue = getDigester(cipherAlgorithm).digest(value);
        }
    }

    return encodedValue;
}

From source file:org.apache.syncope.core.util.Encryptor.java

public String encode(final String value, final CipherAlgorithm cipherAlgorithm)
        throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException,
        InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

    String encodedValue = null;/*from   w w w  .jav a  2s  .  co  m*/

    if (value != null) {
        if (cipherAlgorithm == null || cipherAlgorithm == CipherAlgorithm.AES) {
            final byte[] cleartext = value.getBytes(SyncopeConstants.DEFAULT_ENCODING);

            final Cipher cipher = Cipher.getInstance(CipherAlgorithm.AES.getAlgorithm());
            cipher.init(Cipher.ENCRYPT_MODE, keySpec);

            encodedValue = new String(Base64.encode(cipher.doFinal(cleartext)));
        } else if (cipherAlgorithm == CipherAlgorithm.BCRYPT) {
            encodedValue = BCrypt.hashpw(value, BCrypt.gensalt());
        } else {
            encodedValue = getDigester(cipherAlgorithm).digest(value);
        }
    }

    return encodedValue;
}