Android Utililty Methods SHA256 Hash Create

List of utility methods to do SHA256 Hash Create

Description

The list of methods to do SHA256 Hash Create are organized into topic(s).

Method

byte[]doubleSha256TwoBuffers(byte[] data1, byte[] data2)
double Sha Two Buffers
try {
    MessageDigest digest;
    digest = MessageDigest.getInstance(SHA256);
    digest.update(data1, 0, data1.length);
    digest.update(data2, 0, data2.length);
    return digest.digest(digest.digest());
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e); 
...
StringSHA256(String text)
Converts a String into a SHA-256 hash.
return hashAlgorithm("SHA-256", text);
StringgetHmacSHA256(String key, String input)
Generated a hmac sha256 for a string
Mac mac = Mac.getInstance(HMAC_SHA_2561);
mac.init(new SecretKeySpec(key.getBytes(), HMAC_SHA_2561));
byte[] bs = mac.doFinal(input.getBytes());
return byteArrayToHexString(bs);
byte[]sha256(byte[] data)
sha
return MessageDigest.getInstance("SHA-256").digest(data);
byte[]cipher(int mode, byte[] data, byte[] secret)
cipher
SecretKeySpec secretKeySpec = new SecretKeySpec(sha256(secret),
        "AES");
Cipher c = Cipher.getInstance("AES");
c.init(mode, secretKeySpec);
return c.doFinal(data);