/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-29 11:20:11 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20170829112011-bxa7tmi9qzyo0ai6
* Added Missing Dep. and fixed the real_hash_func method.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
package common;
7
7
 
8
 
import org.bouncycastle.jcajce.provider.digest.SHA3.*;
 
8
import org.bouncycastle.jcajce.provider.digest.*;
9
9
import org.bouncycastle.util.encoders.*;
 
10
import java.security.MessageDigestSpi;
10
11
 
11
12
 
12
13
public class
13
14
Utils {
14
15
  private Utils () {};
15
 
  
 
16
 
16
17
  /**
17
18
   * A hash function that salts the password
18
19
   * in a way that is pseudo dynamic.
22
23
   * @return
23
24
   */
24
25
  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
 
    
29
 
    StringBuilder sb = new StringBuilder ();
30
 
    sb.append (t).insert (b, s);
31
 
    
32
 
    DigestSHA3 md = DigestSHA3 (2048);
33
 
    md.update (sb.toString().getBytes("UTF-8"));
34
 
 
35
 
    return Hex.toHexString (md.digits ());
36
 
  }
37
 
  
 
26
    real_hash_func (String t, String s) {
 
27
      int a = t.getBytes()[0];
 
28
      int b = t.getBytes()[a%t.length()];
 
29
 
 
30
      StringBuilder sb = new StringBuilder ();
 
31
      sb.append (t).insert (b, s);
 
32
 
 
33
      SHA3.DigestSHA3 md = new SHA3.DigestSHA3 (2048);
 
34
      try {
 
35
        md.update (sb.toString().getBytes("UTF-8"));
 
36
      } catch (Exception e) {
 
37
       md.update (sb.toString().getBytes()); 
 
38
      }
 
39
      return Hex.toHexString (md.digest ());
 
40
    }
 
41
 
38
42
  /**
39
43
   * Hash a text with a salt.
40
44
   * 
42
46
   * @return
43
47
   */
44
48
  static public String
45
 
  hash_func (String t) {
46
 
    return real_hash_func(t, common.Config.PW_SALT);
47
 
  }
48
 
  
49
 
  
 
49
    hash_func (String t) {
 
50
      return real_hash_func(t, common.Config.PW_SALT);
 
51
    }
 
52
 
 
53
 
50
54
}