Java Hash Code Calculate generateHash(String serviceUri, String username, String password)

Here you can find the source of generateHash(String serviceUri, String username, String password)

Description

generate Hash

License

Open Source License

Declaration

public static String generateHash(String serviceUri, String username, String password) 

Method Source Code


//package com.java2s;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String generateHash(String serviceUri, String username, String password) {
        StringBuilder hashkey = new StringBuilder();
        String hash = null;/* ww  w.ja  va2  s  .c o  m*/
        hashkey.append(serviceUri);
        hashkey.append(username);
        hashkey.append(password);
        try {
            MessageDigest sha = MessageDigest.getInstance("SHA-1");
            sha.reset();
            hash = hexEncode(sha.digest(hashkey.toString().getBytes()));
        } catch (NoSuchAlgorithmException e) {
            return hashkey.toString();
        }
        return hash;
    }

    private static String hexEncode(byte[] aInput) {
        StringBuffer result = new StringBuffer();
        char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        for (int idx = 0; idx < aInput.length; ++idx) {
            byte b = aInput[idx];
            result.append(digits[(b & 0xf0) >> 4]);
            result.append(digits[b & 0x0f]);
        }
        return result.toString();
    }
}

Related

  1. generateHash(String input)
  2. generateHash(String input, String salt)
  3. generateHash(String item)
  4. generateHash(String plaintext)
  5. generateHash(String plainText, String hashType)
  6. generateHash(String target)
  7. generateHash(String tcString)
  8. generateHashSalt(int length)
  9. generateHashUUID(String digestData)