Here you can find the source of hmacSHA256(byte[] secret, byte[] data)
public static byte[] hmacSHA256(byte[] secret, byte[] data) throws NoSuchAlgorithmException, InvalidKeyException
//package com.java2s; /*//from ww w . j a v a 2 s . c o m * Copyright (c) 2012-2017 ZoxWeb.com LLC. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ import java.security.*; import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; public class Main { public static final String HMAC_SHA_256 = "HmacSHA256"; public static byte[] hmacSHA256(byte[] secret, byte[] data) throws NoSuchAlgorithmException, InvalidKeyException { Mac sha256HMAC = Mac.getInstance(HMAC_SHA_256); SecretKeySpec secret_key = new SecretKeySpec(secret, HMAC_SHA_256); sha256HMAC.init(secret_key); return sha256HMAC.doFinal(data); } }