Code example for Mac

Methods: init

0
	public HMAC(byte [] key)throws NoSuchAlgorithmException, InvalidKeyException{
		 
		hmac = new SecretKeySpec(key, "HmacSHA1" );
		 
		mac  = Mac.getInstance(hmac.getAlgorithm());
		mac.init(hmac);
	} 
	/** 
	 * Calculates the digest of a particular message. 
	 * @param message 
	 * @return 
	 */ 
	public synchronized byte [] calculateDigest(String message){
		mac.reset();
		byte[] digest = mac.doFinal(message.getBytes());
		return(digest);
	} 
	 
	 
}