StreampartyLegacyPwdcheck.java
1.61 KB
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
48
49
50
51
52
53
54
55
56
57
package fi.insomnia.bortal.utilities;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StreampartyLegacyPwdcheck {
private static final Logger logger = LoggerFactory.getLogger(StreampartyLegacyPwdcheck.class);
private static final String streampartyStringToSha(String password) {
String paluu = "";
try {
MessageDigest algo = MessageDigest.getInstance("SHA");
algo.update(password.getBytes(), 0, password.length());
paluu = new BigInteger(1, algo.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return paluu;
}
public static boolean streampartyOldAlgoMatch(String plaintext, String encrypted) {
String salt = encrypted.substring(0, 4);
logger.debug("Got hash: " + salt);
return encrypted.equals(salt + streampartyStringToSha(salt + plaintext.trim()));
}
public static String oldEncode(String password) {
try {
MessageDigest md = MessageDigest.getInstance("SHA");
return new String(Base64.encodeBase64(md.digest(password.getBytes())), "UTF-8");
// return Base64.encode(md.digest(password.getBytes()));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return password;
}
public static boolean oldIsMatch(String password, String encrypted) {
return (encrypted.equals(oldEncode(password)));
}
}