/magstudentportal/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/magstudentportal/trunk
15.1.7 by Gustav Hartvigsson
* added a few things that will help with development
1
package common;
2
15.2.7 by Gustav Hartvigsson
* Started work on design
3
import org.bouncycastle.jcajce.provider.digest.SHA3.*;
4
import org.bouncycastle.util.encoders.*;
5
6
15.1.7 by Gustav Hartvigsson
* added a few things that will help with development
7
public class
8
Utils {
9
  private Utils () {};
10
  
11
  /**
12
   * A hash function that salts the password
13
   * in a way that is pseudo dynamic.
14
   * 
15
   * @param t the text to salt
16
   * @param s the salt
17
   * @return
18
   */
19
  static public String
20
  real_hash_func (String t, String s) {
21
    int a = t.getBytes()[0];
22
    int b = t.getBytes()[a%t.length()];
23
    
15.2.6 by Gustav Hartvigsson
* Started work on the design
24
    StringBuilder sb = new StringBuilder ();
25
    sb.append (t).insert (b, s);
26
    
15.2.7 by Gustav Hartvigsson
* Started work on design
27
    DigestSHA3 md = DigestSHA3 (2048);
28
    md.update (sb.toString().getBytes("UTF-8"));
29
30
    return Hex.toHexString (md.digits ());
15.1.7 by Gustav Hartvigsson
* added a few things that will help with development
31
  }
32
  
33
  /**
34
   * Hash a text with a salt.
35
   * 
36
   * @param t
37
   * @return
38
   */
39
  static public String
40
  hash_func (String t) {
41
    return real_hash_func(t, common.Config.PW_SALT);
42
  }
43
  
44
  
45
}