Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class Main {
    private static String HMAC_ALGORITHM = "HmacSHA1";

    /**
     * This method generates a byte array corresponding to the
     * signed secret using value a signing operator
     * 
     * @param   value   the value used to sign the key
     * @param   secretKey   the key to sign
     * @return   a byte array corresponding to the raw HMAC-SHA1 hash
     */
    public static byte[] hmacSha1(byte[] value, byte[] secretKey) throws RuntimeException {
        try {
            SecretKeySpec signingKey = new SecretKeySpec(secretKey, HMAC_ALGORITHM);
            Mac mac = Mac.getInstance(HMAC_ALGORITHM);
            mac.init(signingKey);
            byte[] rawHmac = mac.doFinal(value);
            return (rawHmac);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}