Example usage for org.apache.commons.codec.digest HmacUtils hmacSha256

List of usage examples for org.apache.commons.codec.digest HmacUtils hmacSha256

Introduction

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

Prototype

public static byte[] hmacSha256(final String key, final String valueToDigest) 

Source Link

Document

Returns a HmacSHA256 Message Authentication Code (MAC) for the given key and value.

Usage

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

/**
 * HmacSHA256/* ww  w  .  j ava  2  s.  c o  m*/
 *
 * @param keyB64 Secret key Base64 encoded
 * @param dataB64 Data to sign Base64 encoded
 * @return HmacSha256 MAC for the given key and data Base64 encoded
 */
public String hmacSha256(String keyB64, String dataB64) {
    validateB64(keyB64);
    validateB64(dataB64);
    final byte[] key = Base64.decodeBase64(keyB64);
    final byte[] data = Base64.decodeBase64(dataB64);

    return Base64.encodeBase64String(HmacUtils.hmacSha256(key, data));
}