labelingsystem-server  Version 0.1.0.0
Crypt Class Reference

Static Public Member Functions

static String base64encode (String text)
 
static String base64decode (String text)
 
static String SHA1 (String text) throws NoSuchAlgorithmException, UnsupportedEncodingException
 
static String MD5 (String text) throws NoSuchAlgorithmException, UnsupportedEncodingException
 
static String generateHash () throws NoSuchAlgorithmException, UnsupportedEncodingException
 

Static Private Member Functions

static String convertToHex (byte[] data)
 

Member Function Documentation

◆ base64decode()

static String base64decode ( String  text)
static
21  {
22  try {
23  String rez = new String(Base64.decodeBase64(text.getBytes("UTF-8")));
24  return rez;
25  } catch (IOException e) {
26  return null;
27  }
28  }

◆ base64encode()

static String base64encode ( String  text)
static
12  {
13  try {
14  String rez = new String(Base64.encodeBase64(text.getBytes("UTF-8")));
15  return rez;
16  } catch (UnsupportedEncodingException e) {
17  return null;
18  }
19  }

◆ convertToHex()

static String convertToHex ( byte[]  data)
staticprivate
30  {
31  StringBuffer buf = new StringBuffer();
32  for (int i = 0; i < data.length; i++) {
33  int halfbyte = (data[i] >>> 4) & 0x0F;
34  int two_halfs = 0;
35  do {
36  if ((0 <= halfbyte) && (halfbyte <= 9)) {
37  buf.append((char) ('0' + halfbyte));
38  } else {
39  buf.append((char) ('a' + (halfbyte - 10)));
40  }
41  halfbyte = data[i] & 0x0F;
42  } while (two_halfs++ < 1);
43  }
44  return buf.toString();
45  }

Referenced by Crypt.SHA1().

◆ generateHash()

static String generateHash ( ) throws NoSuchAlgorithmException, UnsupportedEncodingException
static
68  {
69  UUID newUUID = UUID.randomUUID();
70  String pwd = MD5(newUUID.toString());
71  pwd = pwd.substring(0, 25);
72  return pwd;
73  }

References Crypt.MD5().

Referenced by AuthResource.getHash(), and SQlite.insertUser().

◆ MD5()

static String MD5 ( String  text) throws NoSuchAlgorithmException, UnsupportedEncodingException
static
56  {
57  MessageDigest md;
58  md = MessageDigest.getInstance("MD5");
59  md.update(text.getBytes());
60  byte byteData[] = md.digest();
61  StringBuffer sb = new StringBuffer();
62  for (int i = 0; i < byteData.length; i++) {
63  sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
64  }
65  return sb.toString();
66  }

Referenced by Crypt.generateHash().

◆ SHA1()

static String SHA1 ( String  text) throws NoSuchAlgorithmException, UnsupportedEncodingException
static
47  {
48  MessageDigest md;
49  md = MessageDigest.getInstance("SHA-1");
50  byte[] sha1hash = new byte[40];
51  md.update(text.getBytes("iso-8859-1"), 0, text.length());
52  sha1hash = md.digest();
53  return convertToHex(sha1hash);
54  }

References Crypt.convertToHex().

Referenced by AuthResource.getHash(), SQlite.getUserInfoAndCheckPassword(), and SQlite.insertUser().

v1.utils.crypt.Crypt.MD5
static String MD5(String text)
Definition: Crypt.java:56
v1.utils.crypt.Crypt.convertToHex
static String convertToHex(byte[] data)
Definition: Crypt.java:30