Here you can find the source of getHmacSha256Base64(String key, String data)
public static String getHmacSha256Base64(String key, String data) throws NoSuchAlgorithmException, InvalidKeyException
//package com.java2s; import android.util.Base64; import javax.crypto.Mac; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; public class Main { public static String getHmacSha256Base64(String key, String data) throws NoSuchAlgorithmException, InvalidKeyException { final String encryptionAlgorithm = "HmacSHA256"; SecretKey secretKey = new SecretKeySpec(data.getBytes(), encryptionAlgorithm);//from ww w . ja v a2 s. c o m Mac messageAuthenticationCode = Mac .getInstance(encryptionAlgorithm); messageAuthenticationCode.init(secretKey); messageAuthenticationCode.update(key.getBytes()); byte[] digest = messageAuthenticationCode.doFinal(); return Base64.encodeToString(digest, Base64.NO_WRAP); } }