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

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

Introduction

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

Prototype

public static byte[] sha256(String data) 

Source Link

Usage

From source file:fit5192.util.SHA256.java

public String SHA256Encode(String password) {
    return Hex.encodeHexString(DigestUtils.sha256(password));
}

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

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

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

public String sha256Base64(String dataB64) {
    validateB64(dataB64);
    return Base64.encodeBase64String(DigestUtils.sha256(Base64.decodeBase64(dataB64)));
}

From source file:com.mycompany.monroelabsm.B58.java

public static String encode(byte[] toEncode, byte prefix) {
    //TODO:validate toEncode for correct size
    //TODO:implement an enum for this parameter instead.
    //validate prefix against known prefixes
    byte[] validPrefixes = { 0, //Bitcoin pubkey hash
            5, //Bitcoin script hash
            21, //Bitcoin (compact) public key (proposed)
            52, //Namecoin pubkey hash
            -128, //Private key
            111, //Bitcoin testnet pubkey hash
            -60, //Bitcoin testnet script hash
            -17 //Testnet Private key
    };/*from  ww  w.  j av a  2  s. c  om*/
    Arrays.sort(validPrefixes);
    if (Arrays.binarySearch(validPrefixes, prefix) < 0) {//not found. see https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html
        return "Base58 error: Invalid address prefix byte specified.";
    }

    int size = 21;
    if (prefix == (byte) -128) {
        size = 33;
    }

    byte[] step1 = new byte[size];
    step1[0] = prefix;
    for (int i = 1; i < size; i++) {
        step1[i] = toEncode[i - 1];
    }

    byte[] step2 = new byte[4];
    byte[] step2a = DigestUtils.sha256(DigestUtils.sha256(step1));
    step2[0] = step2a[0];
    step2[1] = step2a[1];
    step2[2] = step2a[2];
    step2[3] = step2a[3];

    byte[] step3 = new byte[size + 4];
    for (int i = 0; i < size; i++) {
        step3[i] = step1[i];
    }
    step3[size] = step2[0];
    step3[size + 1] = step2[1];
    step3[size + 2] = step2[2];
    step3[size + 3] = step2[3];

    String output = Base58.encode(step3);
    return output;
}

From source file:net.sourceforge.jencrypt.lib.Utils.java

public static byte[] hashAESKey(byte[] bytesToHash, final short keySize) {

    byte[] bytesToHashCopy = Arrays.copyOf(bytesToHash, bytesToHash.length);

    switch (keySize) {
    case 128:/*from   w  w w  . ja  va  2  s . c  om*/
        // GNU crypto library hash function implementation of RipeMD128
        IMessageDigest ripeMD128 = new RipeMD128();
        ripeMD128.update(bytesToHashCopy, 0, bytesToHashCopy.length);
        return ripeMD128.digest();
    case 192:
        // GNU crypto library hash function implementation of Tiger
        IMessageDigest tiger = new Tiger();
        tiger.update(bytesToHashCopy, 0, bytesToHashCopy.length);
        return tiger.digest();
    case 256:
        // Apache Commons Codec lib SHA-256
        bytesToHashCopy = DigestUtils.sha256(bytesToHashCopy);
        return bytesToHashCopy;
    default:
        throw new IllegalArgumentException("Key size unkown");
    }
}

From source file:com.twotoasters.android.horizontalimagescroller.io.ImageUrlRequest.java

public String getCacheFileName() {
    if (_cacheFileName == null) {
        String url = _imageToLoadUrl.getUrl();
        String username = _imageToLoadUrl.getUsername();
        String password = _imageToLoadUrl.getPassword();
        String toHash = String.format("url_%1$s_creds_%2$s%3$s_size_%4$dx%5$d", url, username, password,
                _reqWidth, _reqHeight);/*ww w. j av a  2 s. co m*/
        _cacheFileName = new String(Hex.encodeHex(DigestUtils.sha256(toHash)));
    }
    return _cacheFileName;
}

From source file:com.logicoy.pdmp.pmpi.crypto.KeyIVGenerator.java

private void deriveKeyAndIV() {

    try {//from w  w w .jav  a2s. c  o m
        //MessageDigest sha256 = MessageDigest.getInstance("SHA");
        //MessageDigest md5 = MessageDigest.getInstance("MD5");
        // Create Key and IV from password
        byte[] password = this.password.getBytes(Charset.forName("UTF-8"));

        // Key = sha256(password)

        this.key = DigestUtils.sha256(password);
        logger.info("Key length= " + this.key.length);
        // IV = MD5(password)
        //this.iv = md5.digest(this.key);
        this.iv = DigestUtils.md5(this.key);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:io.cloudslang.content.database.utils.SQLUtils.java

@NotNull
public static String computeSessionId(@NotNull final String aString) {
    final byte[] byteData = DigestUtils.sha256(aString.getBytes());
    final StringBuilder sb = new StringBuilder("SQLQuery:");

    for (final byte aByteData : byteData) {
        final String hex = Integer.toHexString(0xFF & aByteData);
        if (hex.length() == 1) {
            sb.append('0');
        }/*  www . j  a  v a  2  s . c  o m*/
        sb.append(hex);
    }
    return sb.toString();
}

From source file:fr.ffremont.mytasks.rest.UserResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response login(@FormParam("login") String login, @FormParam("password") String password)
        throws NotFoundEntity {
    fr.ffremont.mytasks.model.User user = userRepo.findOneByEmail(login);

    if (user == null) {
        LOG.warn("chec de l'authentification : " + login + ":" + password);
        throw new WebApplicationException(Status.UNAUTHORIZED);
    }//from  w  w  w.ja va  2  s  .  c o m

    byte[] hash = DigestUtils.sha256(login + password);
    String myHash = new String(Base64.getEncoder().encode(hash));

    if (!myHash.equals(user.getHash())) {
        LOG.warn("chec de l'authentification : " + login + ":" + password);
        throw new WebApplicationException(Status.UNAUTHORIZED);
    }

    user.setLastConnexion(new Date());
    userRepo.save(user);

    return Response.ok().entity(user).build();
}

From source file:energy.usef.core.repository.SignedMessageHashRepositoryTest.java

@Test
public void testIsSignedContentHashAlreadyPresent() {

    SignedMessageHash signedMessageHash = new SignedMessageHash();
    signedMessageHash.setCreationTime(DateTimeUtil.getCurrentDateTime());
    signedMessageHash.setHashedContent(DigestUtils.sha256(HELLO_USEF_CONTENT));
    repository.persist(signedMessageHash);
    repository.getEntityManager().getTransaction().commit();

    boolean foundMessage = repository.isSignedMessageHashAlreadyPresent(DigestUtils.sha256(HELLO_USEF_CONTENT));
    assertTrue(foundMessage);//from  w  w w.j a  v  a  2  s  .  co  m

    // cleanup
    repository.getEntityManager().getTransaction().begin();
    repository.delete(signedMessageHash);
    repository.getEntityManager().getTransaction().commit();
}