简体   繁体   中英

How to generate sha512 hash with a salt using command line?

I use the below Java snippet to generate a hash password using an input and salt. Is there a way I can get that in Linux command line?

public String getPwd(String input, String salt) {
    MessageDigest md = MessageDigest.getInstance("SHA-512");
    md.update(salt.getBytes(StandardCharsets.UTF_8));
    byte[] pwd= md.digest(input.getBytes(StandardCharsets.UTF_8));
    System.out.println(Base64.encodeBase64URLSafeString(pwd));
}

You can use sha512sum .

cat salt.dat myfile.dat | sha512sum -b

Seems the -b is required for binary input (defaults to text, which can potentially result in different checksums depending on the encoding).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM