wownero
/
wownerujo
Archived
4
0
Fork 0

Fix keystore null (#308)

* avoid crash if input to large

* avoid NPE if wallet key not found
upstream
m2049r 6 years ago committed by GitHub
parent 37244cb9e0
commit 7627e15a48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -66,6 +66,8 @@ public class BitcoinAddressValidator {
byte[] result = new byte[25];
byte[] numBytes = num.toByteArray();
if (numBytes.length > result.length) return null;
if (num.bitLength() == 200) {
System.arraycopy(numBytes, 1, result, 0, 25);
} else {

@ -284,7 +284,9 @@ public class KeyStoreHelper {
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);
@ -305,7 +307,8 @@ public class KeyStoreHelper {
*/
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);