Example #1
0
 /**
  * @param key key
  * @param ser Object
  * @param cipher cipher such as {@linkplain com.hsaknifelib.java.data.Base64Cipher}
  */
 public void put(String key, Object ser, Cipher cipher) {
   try {
     Log.d(TAG, key + " put: " + ser);
     if (ser == null) {
       sp.edit().remove(key).commit();
     } else {
       byte[] bytes = ByteUtil.objectToByte(ser);
       if (cipher != null) bytes = cipher.encrypt(bytes);
       put(key, HexUtil.encodeHexStr(bytes));
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #2
0
 public Object get(String key, Cipher cipher) {
   try {
     String hex = get(key, (String) null);
     if (hex == null) return null;
     byte[] bytes = HexUtil.decodeHex(hex.toCharArray());
     if (cipher != null) bytes = cipher.decrypt(bytes);
     Object obj = ByteUtil.byteToObject(bytes);
     if (isLog) {
       Log.d(TAG, key + " get: " + obj);
     }
     return obj;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }