Java Salt Value Create generateSaltedSHAHash(String algorithm, String input, String salt)

Here you can find the source of generateSaltedSHAHash(String algorithm, String input, String salt)

Description

generate Salted SHA Hash

License

Open Source License

Declaration

static public String generateSaltedSHAHash(String algorithm, String input, String salt)
            throws NoSuchAlgorithmException 

Method Source Code

//package com.java2s;
/**/*w  ww.j a v a  2  s. c om*/
 * OWASP GoatDroid Project
 * 
 * This file is part of the Open Web Application Security Project (OWASP)
 * GoatDroid project. For details, please see
 * https://www.owasp.org/index.php/Projects/OWASP_GoatDroid_Project
 *
 * Copyright (c) 2012 - The OWASP Foundation
 * 
 * GoatDroid is published by OWASP under the GPLv3 license. You should read and accept the
 * LICENSE before you use, modify, and/or redistribute this software.
 * 
 * @author Jack Mannino (Jack.Mannino@owasp.org https://www.owasp.org/index.php/User:Jack_Mannino)
 * @created 2012
 */

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    static public String generateSaltedSHAHash(String algorithm, String input, String salt)
            throws NoSuchAlgorithmException {

        MessageDigest md = MessageDigest.getInstance(algorithm);
        md.update(salt.getBytes());
        byte byteData[] = md.digest(input.getBytes());
        // convert the byte to hex format method 1
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }
        return sb.toString();
    }
}

Related

  1. generateSalt(int length)
  2. generateSalt(int numberOfBytes)
  3. generateSalt(int numBytes)
  4. generateSaltAESPBKDF2()
  5. generateSaltedPassword(final String password, byte[] salt, int iterationsCount, String hmacName)
  6. generateSaltOfLength(int length)
  7. getMd5Salt()
  8. getNewSalt()
  9. getSalt()