@@ -0,0 +1,3473 @@
+package org.adaptlab.chpir.android.survey;%0A%0Aimport java.io.UnsupportedEncodingException;%0Aimport java.security.InvalidAlgorithmParameterException;%0Aimport java.security.InvalidKeyException;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.security.SecureRandom;%0Aimport java.security.spec.InvalidKeySpecException;%0Aimport java.security.spec.KeySpec;%0A%0Aimport javax.crypto.BadPaddingException;%0Aimport javax.crypto.Cipher;%0Aimport javax.crypto.IllegalBlockSizeException;%0Aimport javax.crypto.NoSuchPaddingException;%0Aimport javax.crypto.SecretKey;%0Aimport javax.crypto.SecretKeyFactory;%0Aimport javax.crypto.spec.IvParameterSpec;%0Aimport javax.crypto.spec.PBEKeySpec;%0Aimport javax.crypto.spec.SecretKeySpec;%0A%0Aimport org.apache.commons.codec.binary.Base64;%0A%0Apublic class EncryptUtil %7B%0A%0A    private int iterationCount = 1000;%0A    private int keyLength = 256;%0A    private SecretKey theKey = null;%0A    int saltLength = keyLength / 8;%0A%0A       public String encrypt(String value, String password) throws NoSuchAlgorithmException, InvalidKeySpecException,%0A               NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException,%0A               BadPaddingException, UnsupportedEncodingException %7B%0A%0A           SecureRandom random = new SecureRandom();%0A           byte%5B%5D salt = new byte%5BsaltLength%5D;%0A           random.nextBytes(salt);%0A%0A           SecretKey key = getKey(password, salt);%0A%0A           Cipher cipher = Cipher.getInstance(%22AES/CBC/PKCS5Padding%22);%0A           byte%5B%5D iv = new byte%5Bcipher.getBlockSize()%5D;%0A           random.nextBytes(iv);%0A           IvParameterSpec ivParams = new IvParameterSpec(iv);%0A           cipher.init(Cipher.ENCRYPT_MODE, key, ivParams);%0A           byte%5B%5D cipherText = cipher.doFinal(value.getBytes(%22UTF-8%22));%0A           %0A           return salt + %22::%22 + iv + %22::%22 + new String(cipherText, %22UTF-8%22);%0A       %7D%0A       %0A       public String decrypt(String ciphertext, String password) throws NoSuchAlgorithmException, InvalidKeySpecException,%0A               NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException,%0A               BadPaddingException, UnsupportedEncodingException %7B%0A           %0A           String%5B%5D fields = ciphertext.split(%22::%22);%0A%0A           byte%5B%5D salt = Base64.decodeBase64(fields%5B0%5D);%0A           byte%5B%5D iv = Base64.decodeBase64(fields%5B1%5D);%0A           byte%5B%5D cipherBytes = Base64.decodeBase64(fields%5B2%5D);%0A           %0A           SecretKey key = getKey(password, salt);%0A%0A           Cipher cipher = Cipher.getInstance(%22AES/CBC/PKCS5Padding%22);%0A           IvParameterSpec ivParams = new IvParameterSpec(iv);%0A           cipher.init(Cipher.DECRYPT_MODE, key, ivParams);%0A           byte%5B%5D plaintext = cipher.doFinal(cipherBytes);%0A           %0A           return new String(plaintext , %22UTF-8%22);%0A       %7D%0A%0A       private SecretKey getKey(String password, byte%5B%5D salt) throws NoSuchAlgorithmException, InvalidKeySpecException %7B%0A           if (theKey != null) return theKey;%0A%0A           KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt,%0A                               iterationCount, keyLength);%0A           SecretKeyFactory keyFactory = SecretKeyFactory%0A                               .getInstance(%22PBKDF2WithHmacSHA1%22);%0A           byte%5B%5D keyBytes = keyFactory.generateSecret(keySpec).getEncoded();%0A           SecretKey key = new SecretKeySpec(keyBytes, %22AES%22);%0A           theKey = key;%0A           %0A           return theKey;%0A       %7D%0A%0A%7D%0A

Add encrypt util