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:edu.isi.misd.tagfiler.util.LocalFileChecksum.java

/**
 * Computes a checksum on a file, given the proper message digest
 * implementation//w w w  . ja  va 2s. com
 * 
 * @param file
 *            file to read
 * @param messageDigest
 *            MessageDigest to use
 * @return the checksum bytes of the file
 * @thows FatalException if the checksum cannot be constructed.
 */
public static String computeFileChecksum(File file) throws FatalException {
    if (file == null)
        throw new IllegalArgumentException("file");

    String checksum = null;

    FileInputStream stream = null;
    try {
        stream = new FileInputStream(file);
        if (DigestMethod.SHA512.equals(digestType)) {
            checksum = DigestUtils.sha512Hex(stream);
        } else if (DigestMethod.SHA256.equals(digestType)) {
            checksum = DigestUtils.sha256Hex(stream);
        } else if (DigestMethod.SHA1.equals(digestType)) {
            checksum = DigestUtils.shaHex(stream);
        } else {
            checksum = DigestUtils.md5Hex(stream);
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new FatalException(e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            }
        }
    }
    return checksum;
}

From source file:at.fhjoanneum.swenga.project.audiocracyweb.facades.CustomerFacade.java

@Override
public void edit(Customer entity) {
    if (entity.getId() != null) {
        Customer old = super.find(entity.getId());
        if (!old.getPassword().equals(entity.getPassword())) {
            entity.setPassword(DigestUtils.sha256Hex(entity.getPassword()));
        }//from   w  w  w .  ja  v a 2s  .  c  o  m
    } else {
        entity.setPassword(DigestUtils.sha256Hex(entity.getPassword()));
    }
    super.edit(entity); //To change body of generated methods, choose Tools | Templates.
}

From source file:com.github.aynu.yukar.baseline.provider.domain.auth.CertificationFactory.java

/**
 * ???/*  ww w .  j ava2 s  . c om*/
 * @param account 
 * @param password 
 * @param roles ???()
 * @return ?
 */
public Certification create(final String account, final String password, final String... roles) {
    final Certification certification = new Certification(account, DigestUtils.sha256Hex("password#01"));
    if (roles.length > 0) {
        final Collection<Permission> permissions = new ArrayList<>();
        for (final String role : roles) {
            permissions.add(new Permission(account, role));
        }
        certification.setPermissions(permissions);
    }
    return certification;
}

From source file:com.thoughtworks.go.util.CachedDigestUtilsTest.java

@Test
public void shouldComputeForAGiveStringUsing256SHA() {
    String fingerprint = "Some String";
    String computeMD5 = CachedDigestUtils.sha256Hex(fingerprint);
    assertThat(computeMD5, is(DigestUtils.sha256Hex(fingerprint)));
}

From source file:com.whizzosoftware.hobson.bootstrap.rest.HobsonVerifier.java

@Override
public int verify(String identifier, char[] secret) {
    if (identifier.equals("admin") && hubManager.authenticateAdmin(UserUtil.DEFAULT_USER, UserUtil.DEFAULT_HUB,
            DigestUtils.sha256Hex(new String(secret)))) {
        return RESULT_VALID;
    } else {//from   ww  w.ja v a  2 s.  co m
        return RESULT_INVALID;
    }
}

From source file:com.monitor.baseservice.utils.XCodeUtil.java

public static String getSHA256(InputStream is) throws IOException {
    try {/* w w  w .ja v a  2s .  c o  m*/
        return DigestUtils.sha256Hex(is);
    } finally {
        is.close();
    }
}

From source file:net.bryansaunders.jee6divelog.util.HashUtilsTest.java

/**
 * Tests SHA-256 Hashing.//from  ww w.j a  v a 2s. co m
 */
@Test
public void getSha256Hash() {
    final String original = "Hash Me!";
    final String expectedHash = DigestUtils.sha256Hex(original);

    assertEquals(expectedHash, HashUtils.toSha256(original));
}

From source file:at.fhjoanneum.ima.swenga.webshop.facades.CustomerFacade.java

@Override
public void create(Customer entity) {
    entity.setPassword(DigestUtils.sha256Hex(entity.getPassword()));
    super.create(entity); //To change body of generated methods, choose Tools | Templates. 
}

From source file:com.monitor.baseservice.utils.XCodeUtil.java

public static String getSHA256(String data) throws Exception {
    return DigestUtils.sha256Hex(data);
}

From source file:com.thoughtworks.go.util.CachedDigestUtilsTest.java

@Test
public void shouldComputeForAnEmptyStringUsing256SHA() {
    String fingerprint = "";
    String computeMD5 = CachedDigestUtils.sha256Hex(fingerprint);
    assertThat(computeMD5, is(DigestUtils.sha256Hex(fingerprint)));
}