/magstudentportal/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/magstudentportal/trunk

« back to all changes in this revision

Viewing changes to src/main/java/common/Utils.java

  • Committer: Gustav Hartvigsson
  • Date: 2017-08-28 14:01:22 UTC
  • mfrom: (15.1.10 magstudentportal-more-db)
  • Revision ID: gustav.hartvigsson@gmail.com-20170828140122-dfqs6oxweh0zjzlj
* Merged stuff into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package common;
 
2
 
 
3
import org.bouncycastle.jcajce.provider.digest.SHA3.*;
 
4
import org.bouncycastle.util.encoders.*;
 
5
 
 
6
 
 
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
    
 
24
    StringBuilder sb = new StringBuilder ();
 
25
    sb.append (t).insert (b, s);
 
26
    
 
27
    DigestSHA3 md = DigestSHA3 (2048);
 
28
    md.update (sb.toString().getBytes("UTF-8"));
 
29
 
 
30
    return Hex.toHexString (md.digits ());
 
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
}