Java Digest digestWithSalt(String password, byte[] salt, String algorithm)

Here you can find the source of digestWithSalt(String password, byte[] salt, String algorithm)

Description

digest With Salt

License

Open Source License

Declaration

public static byte[] digestWithSalt(String password, byte[] salt, String algorithm) 

Method Source Code


//package com.java2s;
/*//from w  w  w .  j a  v a 2 s. c o  m
 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Florent Guillaume
 */

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

public class Main {
    public static byte[] digestWithSalt(String password, byte[] salt, String algorithm) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            md.update(password.getBytes("UTF-8"));
            md.update(salt);
            return md.digest();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(algorithm, e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. digestString(MessageDigest md, String s)
  2. digestString(String input)
  3. digestString(String pass, String algorithm)
  4. digestString(String pass, String algorithm)
  5. digestThenEncodePasswordForLDAP(String algorithm, String credentials)