/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
20 by Gustav Hartvigsson
* Added Missing Dep. and fixed the real_hash_func method.
8
import org.bouncycastle.jcajce.provider.digest.*;
15.2.7 by Gustav Hartvigsson
* Started work on design
9
import org.bouncycastle.util.encoders.*;
20 by Gustav Hartvigsson
* Added Missing Dep. and fixed the real_hash_func method.
10
import java.security.MessageDigestSpi;
15.2.7 by Gustav Hartvigsson
* Started work on design
11
12
15.1.7 by Gustav Hartvigsson
* added a few things that will help with development
13
public class
14
Utils {
15
  private Utils () {};
20 by Gustav Hartvigsson
* Added Missing Dep. and fixed the real_hash_func method.
16
15.1.7 by Gustav Hartvigsson
* added a few things that will help with development
17
  /**
18
   * A hash function that salts the password
19
   * in a way that is pseudo dynamic.
20
   * 
21
   * @param t the text to salt
22
   * @param s the salt
23
   * @return
24
   */
25
  static public String
22 by Gustav Hartvigsson
* made the @Inject work.
26
  real_hash_func (String t, String s) {
27
    int a = t.getBytes()[0];
28
    int b = s.getBytes()[a % s.length()] % s.length ();
29
30
    StringBuilder sb = new StringBuilder ();
31
    sb.append (t).insert (b, s);
32
33
    SHA3.DigestSHA3 md = new SHA3.DigestSHA3 (512);
34
    try {
35
      md.update (sb.toString().getBytes("UTF-8"));
36
    } catch (Exception e) {
37
     md.update (sb.toString().getBytes());
20 by Gustav Hartvigsson
* Added Missing Dep. and fixed the real_hash_func method.
38
    }
22 by Gustav Hartvigsson
* made the @Inject work.
39
    return Hex.toHexString (md.digest ());
40
  }
20 by Gustav Hartvigsson
* Added Missing Dep. and fixed the real_hash_func method.
41
15.1.7 by Gustav Hartvigsson
* added a few things that will help with development
42
  /**
43
   * Hash a text with a salt.
44
   * 
45
   * @param t
46
   * @return
47
   */
48
  static public String
22 by Gustav Hartvigsson
* made the @Inject work.
49
  hash_func (String t) {
50
    return real_hash_func(t, common.Config.PW_SALT);
51
  }
20 by Gustav Hartvigsson
* Added Missing Dep. and fixed the real_hash_func method.
52
53
15.1.7 by Gustav Hartvigsson
* added a few things that will help with development
54
}