From c4927caf06f150d825e7f92452552acc46be9eeb Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 4 Feb 2020 18:00:43 -0600 Subject: [PATCH] Don't try to decrypt empty strings String will be empty when removing an account after restoring a backup --- app/src/main/java/org/tasks/security/KeyStoreEncryption.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/org/tasks/security/KeyStoreEncryption.java b/app/src/main/java/org/tasks/security/KeyStoreEncryption.java index 31b9b3699..2be095f0c 100644 --- a/app/src/main/java/org/tasks/security/KeyStoreEncryption.java +++ b/app/src/main/java/org/tasks/security/KeyStoreEncryption.java @@ -6,6 +6,7 @@ import android.security.keystore.KeyGenParameterSpec; import android.security.keystore.KeyProperties; import android.util.Base64; import androidx.annotation.RequiresApi; +import com.google.common.base.Strings; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -70,6 +71,10 @@ public class KeyStoreEncryption implements Encryption { @Override public String decrypt(String text) { + if (Strings.isNullOrEmpty(text)) { + return null; + } + byte[] decoded = Base64.decode(text, Base64.DEFAULT); byte[] iv = Arrays.copyOfRange(decoded, 0, GCM_IV_LENGTH); Cipher cipher = getCipher(Cipher.DECRYPT_MODE, iv);