PHP到Java(hash sha-1和base64)

时间:2017-02-20 20:36:24

标签: java php base64 sha

php中的代码:

$hash = base64_encode(sha1( $password, TRUE ));

我需要用Java。

String hash = "";
    try {
        MessageDigest crypt =  MessageDigest.getInstance("SHA-1");
        crypt.reset();
        crypt.update(pass.getBytes("UTF-8")); 
        hash = Base64.getEncoder().encodeToString(crypt.digest(pass.getBytes()));
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
        Utilit.LoggingBD(Utilit.getIP(), 12, ex.toString());
        Logger.getLogger(Guard.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, "Ошибка хэширования пароля");
    }
    return hash;

代码有不同的结果。我需要php-code的结果

0 个答案:

没有答案