-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSolrPasswordHash.java
38 lines (33 loc) · 1.06 KB
/
SolrPasswordHash.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;
import org.apache.commons.codec.binary.Base64;
public class SolrPasswordHash {
public static void main (String[] args) {
if (args.length == 0) {
System.err.println("Nothing to do.");
System.exit(1);
}
String pw = args[0];
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-256");
final Random r = new SecureRandom();
byte[] salt = new byte[32];
r.nextBytes(salt);
digest.reset();
digest.update(salt);
byte[] btPass = digest.digest(pw.getBytes(StandardCharsets.UTF_8));
digest.reset();
btPass = digest.digest(btPass);
System.out.println(Base64.encodeBase64String(btPass) + " " +
Base64.encodeBase64String(salt));
System.exit(0);
} catch (NoSuchAlgorithmException e) {
System.err.println("Unknown algorithm: " + e.getMessage());
}
System.exit(2);
}
}