/magstudentportal/trunk

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