Skip to content

Commit

Permalink
Fix keystore null (m2049r#308)
Browse files Browse the repository at this point in the history
* avoid crash if input to large

* avoid NPE if wallet key not found
  • Loading branch information
m2049r authored and crtlib committed Jun 28, 2018
1 parent 97a95fa commit b5d73b2
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,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);
Expand All @@ -305,7 +307,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);
Expand Down

0 comments on commit b5d73b2

Please sign in to comment.