Example usage for org.apache.commons.codec.digest DigestUtils sha256Hex

List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils sha256Hex.

Prototype

public static String sha256Hex(String data) 

Source Link

Usage

From source file:HashCollider.java

/**i
 * @param args the command line arguments
 *//*from w  ww. j a  va  2s .  com*/
public static void main(String[] args) {
    Random random = new Random();
    byte[] nbytes1 = new byte[64];
    byte[] nbytes2 = new byte[64];
    float average = 0;
    // set number of bits for checking collision
    int number_of_bits = 4;
    random.nextBytes(nbytes1);
    random.nextBytes(nbytes2);

    String sha1 = DigestUtils.sha256Hex(nbytes1);
    String sha2 = DigestUtils.sha256Hex(nbytes2);

    String nsh1 = new BigInteger(sha1, 16).toString(2);
    String nsh2 = new BigInteger(sha2, 16).toString(2);
    int i = 0;
    for (int j = 0; j < 5; j++) {
        while (true) {
            if (nsh1.substring(0, number_of_bits - 1).equals(nsh2.substring(0, number_of_bits - 1))) {
                System.out.println(i);
                average += i;
                break;
            }
            i++;
            //            System.out.println("......"+i);
            random.nextBytes(nbytes1);
            random.nextBytes(nbytes2);
            sha1 = DigestUtils.sha256Hex(nbytes1);
            sha2 = DigestUtils.sha256Hex(nbytes2);
            nsh1 = new BigInteger(sha1, 16).toString(2);
            nsh2 = new BigInteger(sha2, 16).toString(2);
        }
        i = 0;
        //        System.out.println(nsh1+"\n"+nsh2);
        random.nextBytes(nbytes1);
        random.nextBytes(nbytes2);
        sha1 = DigestUtils.sha256Hex(nbytes1);
        sha2 = DigestUtils.sha256Hex(nbytes2);
        nsh1 = new BigInteger(sha1, 16).toString(2);
        nsh2 = new BigInteger(sha2, 16).toString(2);

    }
    //
    System.out.println("Average for  " + number_of_bits + " bits is  " + average / 5);

}

From source file:com.atlantex.game.util.PasswordUtils.java

public static String encrypt(String toEncrypt) {
    String encrypted = DigestUtils.sha256Hex(toEncrypt);
    return encrypted;
}

From source file:com.meteocal.business.shared.security.PasswordEncrypter.java

public static String encrypt(String password) {
    return DigestUtils.sha256Hex(password);
}

From source file:com.shadows.liquiblq.common.utils.HashManager.java

public static String SHA256(String text) {
    return DigestUtils.sha256Hex(text);
}

From source file:com.thoughtworks.go.security.CertificateUtil.java

public static String md5Fingerprint(X509Certificate certificate) {
    try {// www. j  a v  a  2 s. co  m
        return DigestUtils.sha256Hex(certificate.getEncoded());
    } catch (GeneralSecurityException gse) {
        throw bomb(gse);
    }
}

From source file:io.java.back.business.UsuarioData.java

public static Usuario selecionarUsuario() {
    Usuario usuario = (Usuario) HibernateUtil.getSessionFactory().openSession()
            .createQuery("from Usuario where login = :login").setString("login", "user").uniqueResult();

    if (usuario == null) {
        usuario = new Usuario();
        usuario.setLogin("ADM-01");
        usuario.setSenha(DigestUtils.sha256Hex("123"));
        usuario.setNome("Administrator");
        usuario.setTipo(Tipo.SUPORTE);/*from   w w  w.ja  v  a2  s  .c  om*/
        usuario.setDataRegistro(new Date());
        usuario.setAtivo(true);

        UsuarioData usuarioBus = new UsuarioData();
        usuarioBus.inserir(usuario);
    }
    return usuario;
}

From source file:io.github.dggodoi.aprendendo.java.backend.business.UsuarioBus.java

public static Usuario selecionarAluno() {
    Usuario aluno = (Usuario) HibernateUtil.getSessionFactory().openSession()
            .createQuery("from Usuario where login = :login").setString("login", "aluno").uniqueResult();

    if (aluno == null) {
        aluno = new Usuario();
        aluno.setLogin("aluno");
        aluno.setSenha(DigestUtils.sha256Hex("123"));
        aluno.setNome("Aluno Teste");
        aluno.setTipo(Tipo.SUPORTE);// www .  j  a va2  s  .  co m
        aluno.setDataRegistro(new Date());
        aluno.setAtivo(true);

        UsuarioBus usuarioBus = new UsuarioBus();
        usuarioBus.inserir(aluno);
    }

    return aluno;
}

From source file:ch.silviowangler.dox.HashGenerator.java

public static String sha256Hex(File file) throws IOException {

    Assert.notNull(file, "file must not be null");

    logger.debug("About to generate SHA-256 hash for file '{}'. Does it exist? {}", file.getAbsolutePath(),
            file.exists());/*from  w w  w.  ja v a2s. c  o  m*/

    InputStream inputStream = new FileInputStream(file);
    return DigestUtils.sha256Hex(inputStream);
}

From source file:airport.services.users.PasswordHashImpl.java

@Override
public String getHashPassword(String password) {
    return DigestUtils.sha256Hex(password);
}

From source file:com.cuebiq.presto.scalar.HashingFunctions.java

@Description("hashes with sha_256")
@ScalarFunction//w  w w .  j  a  v a  2s . c o m
@SqlType(StandardTypes.VARCHAR)
public static Slice sha_256(@SqlType(StandardTypes.VARCHAR) Slice string) {

    return Slices.utf8Slice(DigestUtils.sha256Hex(string.toStringUtf8()));

}