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
|
package common;
import org.bouncycastle.jcajce.provider.digest.SHA3.*;
import org.bouncycastle.util.encoders.*;
public class
Utils {
private Utils () {};
/**
* A hash function that salts the password
* in a way that is pseudo dynamic.
*
* @param t the text to salt
* @param s the salt
* @return
*/
static public String
real_hash_func (String t, String s) {
int a = t.getBytes()[0];
int b = t.getBytes()[a%t.length()];
StringBuilder sb = new StringBuilder ();
sb.append (t).insert (b, s);
DigestSHA3 md = DigestSHA3 (2048);
md.update (sb.toString().getBytes("UTF-8"));
return Hex.toHexString (md.digits ());
}
/**
* Hash a text with a salt.
*
* @param t
* @return
*/
static public String
hash_func (String t) {
return real_hash_func(t, common.Config.PW_SALT);
}
}
|