Advertisement
Lauda

Untitled

May 12th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package functions;
  2.  
  3. import java.security.MessageDigest;
  4. import java.security.NoSuchAlgorithmException;
  5.  
  6. import org.json.JSONArray;
  7. import org.json.JSONException;
  8. import org.json.JSONObject;
  9.  
  10. public class Utils {
  11.  
  12.     public Utils()
  13.     {
  14.         super();
  15.     }
  16.    
  17.     public JSONArray genJSONData(String msg, String msgType, Boolean b, String url)
  18.     {
  19.         JSONArray tmpArray = new JSONArray();
  20.         JSONObject main = new JSONObject();
  21.        
  22.         try {
  23.         main.put("message", msg);
  24.         main.put("err", b);
  25.         main.put("url", url);
  26.         main.put("msgType", msgType);
  27.         tmpArray.put(main);
  28.        
  29.         } catch (JSONException e) {
  30.             // TODO Auto-generated catch block
  31.             e.printStackTrace();
  32.         }
  33.         return tmpArray;
  34.     }
  35.    
  36.     public String getMD5(String plainPass) throws NoSuchAlgorithmException
  37.     {
  38.         MessageDigest mdAlgorithm = MessageDigest.getInstance("MD5");
  39.         mdAlgorithm.update(plainPass.getBytes());
  40.  
  41.         byte[] digest = mdAlgorithm.digest();
  42.         StringBuffer hexString = new StringBuffer();
  43.  
  44.         for (int i = 0; i < digest.length; i++) {
  45.             plainPass = Integer.toHexString(0xFF & digest[i]);
  46.  
  47.             if (plainPass.length() < 2) {
  48.                 plainPass = "0" + plainPass;
  49.             }
  50.  
  51.             hexString.append(plainPass);
  52.         }
  53.            
  54.         return hexString.toString();
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement