get Hmac Sha - Android java.security

Android examples for java.security:HMAC

Description

get Hmac Sha

Demo Code


//package com.java2s;

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

public class Main {
    /**/*from  w w  w  .j a va  2  s.c o m*/
     * 
     * @param content
     * @param key
     * @return
     * @throws Exception
     */
    public static byte[] getHmacSha1(byte[] content, byte[] key)
            throws Exception {
        SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
        Mac mac = Mac.getInstance(signingKey.getAlgorithm());
        mac.init(signingKey);
        return mac.doFinal(content);
    }
}

Related Tutorials