-
Notifications
You must be signed in to change notification settings - Fork 6
/
App.java
47 lines (40 loc) · 1.59 KB
/
App.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
39
40
41
42
43
44
45
46
47
package com.zhyufeng.pbkdf2;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
/**
* Hello world!
*
*/
public class App
{
//TEST
public static void main(String[] args){
String password = "password";
String salt = "XaIs9vQgmLujKHZG4/B3dNTbeP2PyaVKySTirZznBrE=";
String pbkstr = "PBKDF2$sha1$98$XaIs9vQgmLujKHZG4/B3dNTbeP2PyaVKySTirZznBrE=$2DX/HZDTojVbfgAIdozBi6CihjWP1+akYnh/h9uQfIVl6pLoAiwJe1ey2WW2BnT+";
String ciphertext;
Boolean match;
try {
//test case of mosquitto-auth-plug pbkdf2-check.c
ciphertext = PBKDF2HmacSHA1.encryptedPassword(password,salt);
System.out.println(ciphertext);
System.out.println("Checking password ["+"password"+"] for "+"pbkstr");
match = ciphertext.equals(pbkstr);
System.out.println("match: "+match );
salt = PBKDF2HmacSHA1.generateSalt();
System.out.println("salt: "+salt );
String storedPassword = ciphertext;
System.out.println("Checking passwordOriginal ["+password+"] for "+storedPassword);
match = PBKDF2HmacSHA1.validatePassword(password,storedPassword);
System.out.println("match: "+match );
password = "password1";
System.out.println("Checking passwordOriginal ["+password+"] for "+storedPassword);
match = PBKDF2HmacSHA1.validatePassword(password,storedPassword);
System.out.println("match: "+match );
} catch (NoSuchAlgorithmException e) {
System.out.println("NoSuchAlgorithmException");
} catch (InvalidKeySpecException e) {
System.out.println("InvalidKeySpecException");
}
}
}