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

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

Introduction

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

Prototype

public static Mac getHmacSha512(final byte[] key) 

Source Link

Document

Returns an initialized Mac for the HmacSHA512 algorithm.

Usage

From source file:io.cloudslang.content.azure.services.AuthorizationTokenImpl.java

@NotNull
public static String getToken(@NotNull final String identifier, @NotNull final String primaryOrSecondaryKey,
        @NotNull final Date expiryDate) {
    final Mac sha512Hmac = HmacUtils.getHmacSha512(primaryOrSecondaryKey.getBytes(UTF_8));
    final String dataToSign = String.format("%s\n%s", identifier, DateUtilities.formatDate(expiryDate));
    final byte[] encodedBytes = Base64.encodeBase64(sha512Hmac.doFinal(dataToSign.getBytes(UTF_8)));
    final String encodedString = new String(encodedBytes, UTF_8);
    return String.format(SHARED_ACCESS_SIGNATURE, identifier, DateUtilities.formatDate(expiryDate),
            encodedString);//from   w  w w  . java 2  s . co m
}