Java HMAC HMAC(String username, BigInteger nonce, String hashedPassword)

Here you can find the source of HMAC(String username, BigInteger nonce, String hashedPassword)

Description

This will Find HMAC and Append it to

License

Open Source License

Parameter

Parameter Description
username a parameter
nonce a parameter
hashedPassword a parameter

Exception

Parameter Description
NoSuchAlgorithmException an exception

Declaration

public static String HMAC(String username, BigInteger nonce, String hashedPassword)
        throws NoSuchAlgorithmException 

Method Source Code

//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;
    }
}

Related

  1. hmac(byte key[], byte text[])
  2. hmac(String hash, String data, String key)
  3. hmac(String msg, String keyString)
  4. hmac_sha(String crypto, byte[] keyBytes, byte[] text)
  5. hmac_sha(String crypto, byte[] keyBytes, byte[] text)
  6. hmacDigest(String message, String secretKey, String algorithm)
  7. hmacEncode(String algorithm, String input, String privateKey)