1 package de.dhbwloe.campusapp;
3 import android.view.View;
4 import android.view.ViewGroup;
5 import android.widget.AdapterView;
7 import java.security.MessageDigest;
8 import java.security.NoSuchAlgorithmException;
10 import javax.crypto.Cipher;
11 import javax.crypto.spec.SecretKeySpec;
14 * Created by pk910 on 25.01.2016.
18 public static final String md5(final String s) {
19 final String MD5 = "MD5";
22 MessageDigest digest = java.security.MessageDigest.getInstance(MD5);
23 digest.update(s.getBytes());
24 byte messageDigest[] = digest.digest();
27 StringBuilder hexString = new StringBuilder();
28 for (byte aMessageDigest : messageDigest) {
29 String h = Integer.toHexString(0xFF & aMessageDigest);
30 while (h.length() < 2)
34 return hexString.toString();
36 } catch (NoSuchAlgorithmException e) {
42 public static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
43 SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
44 Cipher cipher = Cipher.getInstance("AES");
45 cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
46 byte[] encrypted = cipher.doFinal(clear);
50 public static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
51 SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
52 Cipher cipher = Cipher.getInstance("AES");
53 cipher.init(Cipher.DECRYPT_MODE, skeySpec);
54 byte[] decrypted = cipher.doFinal(encrypted);
58 public static void removeAllChildViews(ViewGroup viewGroup) {
59 for (int i = 0; i < viewGroup.getChildCount(); i++) {
60 View child = viewGroup.getChildAt(i);
61 if (child instanceof ViewGroup) {
62 if (child instanceof AdapterView) {
63 viewGroup.removeView(child);
66 removeAllChildViews(((ViewGroup) child));
68 viewGroup.removeView(child);