encode byte array Hmac SHA - Java Security

Java examples for Security:SHA

Description

encode byte array Hmac SHA

Demo Code


//package com.java2s;

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

public class Main {


    public static byte[] encodeHmacSHA(byte[] data, byte[] key) {
        try {//from w  w  w .j  a v a  2 s .  c o m
            String method = "HmacSHA1";
            SecretKeySpec k = new SecretKeySpec(key, method);
            Mac mac = Mac.getInstance(method);
            mac.init(k);
            return mac.doFinal(data);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials