From 1a9e4fbdfc1748fa798a0b520d5d09f676309632 Mon Sep 17 00:00:00 2001 From: m2049r Date: Sun, 10 Jun 2018 10:57:24 +0200 Subject: [PATCH] Fix keystore null (#308) * avoid crash if input to large * avoid NPE if wallet key not found --- .../java/com/m2049r/aeonwallet/util/KeyStoreHelper.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/m2049r/aeonwallet/util/KeyStoreHelper.java b/app/src/main/java/com/m2049r/aeonwallet/util/KeyStoreHelper.java index 6d11c065ef..bb689739cb 100644 --- a/app/src/main/java/com/m2049r/aeonwallet/util/KeyStoreHelper.java +++ b/app/src/main/java/com/m2049r/aeonwallet/util/KeyStoreHelper.java @@ -260,7 +260,9 @@ private static byte[] encrypt(String alias, byte[] data) { private static byte[] decrypt(String alias, byte[] data) { try { - PrivateKey privateKey = getPrivateKeyEntry(alias).getPrivateKey(); + KeyStore.PrivateKeyEntry pke = getPrivateKeyEntry(alias); + if (pke == null) return null; + PrivateKey privateKey = pke.getPrivateKey(); Cipher cipher = Cipher.getInstance(SecurityConstants.CIPHER_RSA_ECB_PKCS1); cipher.init(Cipher.DECRYPT_MODE, privateKey); @@ -281,7 +283,8 @@ private static byte[] decrypt(String alias, byte[] data) { */ private static byte[] signData(String alias, byte[] data) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { - + KeyStore.PrivateKeyEntry pke = getPrivateKeyEntry(alias); + if (pke == null) return null; PrivateKey privateKey = getPrivateKeyEntry(alias).getPrivateKey(); Signature s = Signature.getInstance(SecurityConstants.SIGNATURE_SHA256withRSA); s.initSign(privateKey);