@Deprecated
 private static String encrypt(String cleartext) {
   if (cleartext == null || cleartext.length() == 0) {
     return cleartext;
   }
   try {
     final Cipher cipher = Cipher.getInstance(AES_KEY_ALG, PROVIDER);
     cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(SecurePreferencesOld.sKey, AES_KEY_ALG));
     return SecurePreferencesOld.encode(cipher.doFinal(cleartext.getBytes("UTF-8")));
   } catch (Exception e) {
     if (sLoggingEnabled) {
       Log.w(TAG, "encrypt", e);
     }
     return null;
   }
 }
  @Deprecated
  private static String generateAesKeyValue() throws NoSuchAlgorithmException {
    // Do *not* seed secureRandom! Automatically seeded from system entropy
    final SecureRandom random = new SecureRandom();

    // Use the largest AES key length which is supported by the OS
    final KeyGenerator generator = KeyGenerator.getInstance("AES");
    try {
      generator.init(KEY_SIZE, random);
    } catch (Exception e) {
      try {
        generator.init(192, random);
      } catch (Exception e1) {
        generator.init(128, random);
      }
    }
    return SecurePreferencesOld.encode(generator.generateKey().getEncoded());
  }
  private static String generateAesKeyName(Context context)
      throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException {
    final char[] password = context.getPackageName().toCharArray();

    final byte[] salt = getDeviceSerialNumber(context).getBytes();

    SecretKey key;
    try {
      // TODO: what if there's an OS upgrade and now supports the primary
      // PBE
      key =
          SecurePreferencesOld.generatePBEKey(
              password, salt, PRIMARY_PBE_KEY_ALG, ITERATIONS, KEY_SIZE);
    } catch (NoSuchAlgorithmException e) {
      // older devices may not support the have the implementation try
      // with a weaker
      // algorthm
      key =
          SecurePreferencesOld.generatePBEKey(
              password, salt, BACKUP_PBE_KEY_ALG, ITERATIONS, KEY_SIZE);
    }
    return SecurePreferencesOld.encode(key.getEncoded());
  }