Java examples for Security:SHA
get Hmac SHA Hash
//package com.java2s; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; public class Main { public static byte[] getHmacSHA1(String inStr, String appSecet) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException { Mac mac = null;// w w w .j a va 2s . com try { mac = Mac.getInstance("HmacSHA1"); SecretKeySpec secret = new SecretKeySpec( appSecet.getBytes("UTF-8"), mac.getAlgorithm()); mac.init(secret); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); return null; } return mac.doFinal(inStr.getBytes()); } }