orhanobut / hawk

✔️ Secure, simple key-value storage for Android
Apache License 2.0
3.98k stars 388 forks source link

Hawk Decrypt failed #182

Open AlexTip opened 7 years ago

AlexTip commented 7 years ago

Hello, I have trouble with getting value in this case:

  1. I use init in my Application file Hawk.init(applicationContext).build()

  2. When user logouts I deleteAll Hawk.deleteAll()

  3. And I delete all application files -

    public static void clearApplicationData(Context context){
        File cache = context.getCacheDir();
        File appDir = new File(cache.getParent());
        if (appDir.exists()) {
            String[] children = appDir.list();
            for (String s : children) {
                if (!s.equals("lib")) {
                    deleteDir(new File(appDir, s));
                }
            }
        }
    }
  4. And when user log in again (current session) I put user data to Hawk Hawk.put(KEY_ID, id)

  1. When app restart method Hawk.get(KEY_ID) returns null And in log
    E/Hawk: onLog: Hawk.get ->  Decrypt failed: The message could not be decrypted successfully.It has either been tampered with or the wrong resource is being decrypted.
    E/Hawk: onLog: Hawk.get -> Decrypt failed

    But Hawk.contains(KEY_ID) return true

But when after 3 step, restart app, all work fine......

In Your documentation to method deleteAll written

Clears the storage, note that crypto data won't be deleted such as salt key etc.
Use resetCrypto in order to deleteAll crypto information

But I don't find method resetCrypto()

Android version - any; Phone model - any; Version Hawk - 2.0.1;

Thanks.

orhanobut commented 6 years ago

I'll take a look for this one. 👍

erleizh commented 5 years ago

After the app is updated

Decrypt failed: The message could not be decrypted successfully. It has either been tampered with or the wrong resource is being decrypted.

May be the reason for the java bean to add a new field?