Java SHA256 sha256(String password, String salt)

Here you can find the source of sha256(String password, String salt)

Description

sha

License

Apache License

Declaration

public static String sha256(String password, String salt)
            throws NoSuchAlgorithmException, UnsupportedEncodingException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String sha256(String password, String salt)
            throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        digest.reset();/*from   www  .j ava2s .  com*/
        digest.update(salt.getBytes());

        byte[] mdbytes = digest.digest(password.getBytes("UTF-8"));

        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < mdbytes.length; i++) {
            hexString.append(Integer.toHexString(0xFF & mdbytes[i]));
        }

        return hexString.toString();
    }
}

Related

  1. sha256(String base)
  2. sha256(String data)
  3. sha256(String Input)
  4. SHA256(String input)
  5. sha256(String message)
  6. sha256(String plainText)
  7. sha256(String raw)
  8. sha256(String s)
  9. sha256(String src)