Here you can find the source of HMAC(String username, BigInteger nonce, String hashedPassword)
Parameter | Description |
---|---|
username | a parameter |
nonce | a parameter |
hashedPassword | a parameter |
Parameter | Description |
---|---|
NoSuchAlgorithmException | an exception |
public static String HMAC(String username, BigInteger nonce, String hashedPassword) throws NoSuchAlgorithmException
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**/* w w w. j a v a 2 s .c o m*/ * * This will Find HMAC and Append it to * * @param username * @param nonce * @param hashedPassword * @return * @throws NoSuchAlgorithmException */ public static String HMAC(String username, BigInteger nonce, String hashedPassword) throws NoSuchAlgorithmException { String hash = null; StringBuilder sb = new StringBuilder(14); sb.append(username).append(" ").append(nonce).append(" ").append(hashedPassword); String appended = sb.toString(); try { hash = makeSHA512Hash(appended); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return hash; } public static String makeSHA512Hash(String input) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md = MessageDigest.getInstance("SHA-512"); md.reset(); byte[] buffer = input.getBytes("UTF-8"); md.update(buffer); byte[] digest = md.digest(); String hexStr = ""; for (int i = 0; i < digest.length; i++) { hexStr += Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1); } return hexStr; } }