-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSql_id.java
34 lines (27 loc) · 1.33 KB
/
Sql_id.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
package iNuage;
import java.security.SecureRandom;
import java.util.Base64;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
public class Sql_id {
public static String driver = "com.mysql.jdbc.Driver";
public static String connection = "jdbc:mysql://cs3.calstatela.edu/cs3220stu97";
public static String user = "cs3220stu97";
public static String password = "TZ*JTLXb";
private static final int iterations = 2000;
private static final int saltLen = 16;
private static final int desiredKeyLen = 128;
public static String getSaltedHash(String password) throws Exception {
byte[] salt = SecureRandom.getInstance("SHA1PRNG").generateSeed(saltLen);
return Base64.getEncoder().encodeToString(salt) + "$" + hash(password, salt);
}
public static String hash(String password, byte[] salt) throws Exception {
if (password == null || password.length() == 0)
throw new IllegalArgumentException("Empty passwords are not supported.");
SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
SecretKey key = f.generateSecret(new PBEKeySpec(
password.toCharArray(), salt, iterations, desiredKeyLen));
return Base64.getEncoder().encodeToString(key.getEncoded());
}
}