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

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

Introduction

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

Prototype

public static byte[] sha512(String data) 

Source Link

Usage

From source file:com.bloatit.framework.utils.Hash.java

/**
 * From a password and a salt, returns the corresponding digest
 * /*from w  ww  . java2 s.co m*/
 * @param password The password to encrypt
 * @param salt The salt
 * @return String The digested password in base64
 */
public static String calculateHash(final String password, final String salt) {
    byte[] value = (password + salt).getBytes();
    for (int i = 0; i < ITERATION_NUMBER; i++) {
        value = DigestUtils.sha512(value);
    }
    return Base64.encodeBase64String(value);
}

From source file:dtu.ds.warnme.app.utils.SecurityUtils.java

public static String hashSHA512Base64(String stringToHash) {
    if (StringUtils.isEmpty(stringToHash)) {
        return StringUtils.EMPTY;
    }/*from   ww  w .  jav  a  2s  .  c  o  m*/
    try {
        byte[] bytes = stringToHash.getBytes(CHARSET_UTF8);
        byte[] md5bytes = DigestUtils.sha512(bytes);
        byte[] base64bytes = Base64.encodeBase64(md5bytes);
        return new String(base64bytes, CHARSET_UTF8);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "This system does not support required hashing algorithms.", e);
        throw new IllegalStateException("This system does not support required hashing algorithms.", e);
    }
}

From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java

public String sha512(String data) {
    return Base64.encodeBase64String(DigestUtils.sha512(data));
}

From source file:guru.bubl.module.model.User.java

private String encode(String password) {
    if (password == null)
        throw new IllegalArgumentException("Missing password");

    // the salt is composed of the email and salt. This way, two member objects with
    // the same email and same password can have two different hash
    return Base64.encodeBase64URLSafeString(DigestUtils.sha512(password + salt));
}

From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java

public String sha512Base64(String dataB64) {
    validateB64(dataB64);
    return Base64.encodeBase64String(DigestUtils.sha512(Base64.decodeBase64(dataB64)));
}

From source file:guru.bubl.module.model.UserTest.java

@Test
public void password_is_encoded_with_salt() {
    String password = "Potatoe";
    User user = User.withEmail("roger@lamothe.org").password(password);
    String expectedPasswordHash = Base64.encodeBase64URLSafeString(DigestUtils.sha512(password + user.salt()));
    assertThat(user.passwordHash(), is(expectedPasswordHash));
}

From source file:dtu.ds.warnme.utils.SecurityUtils.java

public static String hashSHA512Base64(String stringToHash) throws UnsupportedEncodingException {
    byte[] bytes = stringToHash.getBytes(CHARSET_UTF8);
    byte[] sha512bytes = DigestUtils.sha512(bytes);
    byte[] base64bytes = Base64.encodeBase64(sha512bytes);
    return new String(base64bytes, CHARSET_UTF8);
}

From source file:com.github.aynu.mosir.core.standard.util.CodecHelper.java

/**
 * SHA-512// w  ww  .j  a  v a2  s.c  om
 * <dl>
 * <dt>?
 * <dd>SHA-512?????
 * </dl>
 * @param data 
 * @return ??
 */
public static byte[] sha512(final byte[] data) {
    return DigestUtils.sha512(data);
}

From source file:org.apache.ace.authentication.processor.password.PasswordAuthenticationProcessor.java

/**
 * Hashes a given password using the current set hash method.
 * /*from  ww  w .ja v a 2  s . com*/
 * @param password the password to hash, should not be <code>null</code>.
 * @return the hashed password, never <code>null</code>.
 */
private Object hashPassword(Object password) {
    if ("none".equalsIgnoreCase(m_passwordHashMethod)) {
        // Very special ROT26 hashing method...
        return password;
    }

    if ("md5".equalsIgnoreCase(m_passwordHashMethod)) {
        if (password instanceof byte[]) {
            return DigestUtils.md5((byte[]) password);
        }
        return DigestUtils.md5((String) password);
    }
    if ("sha1".equalsIgnoreCase(m_passwordHashMethod)) {
        if (password instanceof byte[]) {
            return DigestUtils.sha((byte[]) password);
        }
        return DigestUtils.sha((String) password);
    }
    if ("sha256".equalsIgnoreCase(m_passwordHashMethod)) {
        if (password instanceof byte[]) {
            return DigestUtils.sha256((byte[]) password);
        }
        return DigestUtils.sha256((String) password);
    }
    if ("sha384".equalsIgnoreCase(m_passwordHashMethod)) {
        if (password instanceof byte[]) {
            return DigestUtils.sha384((byte[]) password);
        }
        return DigestUtils.sha384((String) password);
    }
    if ("sha512".equalsIgnoreCase(m_passwordHashMethod)) {
        if (password instanceof byte[]) {
            return DigestUtils.sha512((byte[]) password);
        }
        return DigestUtils.sha512((String) password);
    }
    return password;
}

From source file:org.saadahmed.snowcrystal.SnowCrystal.java

public static String sha512Base64URLSafe() {
    return Base64.encodeBase64URLSafeString(DigestUtils.sha512(SnowCrystal.newId().unwrap()));
}