more clearing private bits

This commit is contained in:
Craig Raw 2020-05-19 16:41:37 +02:00
parent d2bd335e76
commit 06de1d7e14
6 changed files with 20 additions and 2 deletions

View file

@ -111,6 +111,7 @@ public class Utils {
int srcPos = isFirstByteOnlyForSign ? 1 : 0;
int destPos = numBytes - length;
System.arraycopy(src, srcPos, dest, destPos, length);
Arrays.fill(src, (byte)0);
return dest;
}

View file

@ -45,7 +45,7 @@ public class ECIESKeyCrypter implements AsymmetricKeyCrypter {
byte[] hmacInput = Arrays.copyOfRange(decoded, 0, decoded.length - 32);
if(!Arrays.equals(mac, hmac256(key_m, hmacInput))) {
throw new InvalidPasswordException();
throw new InvalidPasswordException("The password was invalid");
}
return aesKeyCrypter.decrypt(new EncryptedData(iv, ciphertext, null, null), new Key(key_e, null, null));

View file

@ -699,6 +699,12 @@ public class ECKey implements EncryptableItem {
return Utils.bigIntegerToBytes(getPrivKey(), 32);
}
public void clear() {
for(int i = 0; i < priv.bitLength(); i++) {
priv.clearBit(i);
}
}
/**
* Returns the creation time of this key or zero if the key was deserialized from a version that did not store
* that data.

View file

@ -27,6 +27,5 @@ public class Key {
public void clear() {
Arrays.fill(keyBytes, (byte)0);
Arrays.fill(salt, (byte)0);
}
}

View file

@ -202,4 +202,10 @@ public class Keystore {
seed = seed.decrypt(key);
}
}
public void clearPrivate() {
if(hasSeed()) {
seed.clear();
}
}
}

View file

@ -198,4 +198,10 @@ public class Wallet {
keystore.decrypt(key);
}
}
public void clearPrivate() {
for(Keystore keystore : keystores) {
keystore.clearPrivate();
}
}
}