mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
preserve id when encrypting or decrypting seeds or private keys
This commit is contained in:
parent
485e8c825b
commit
f407547c47
2 changed files with 13 additions and 4 deletions
|
@ -184,6 +184,7 @@ public class DeterministicSeed extends Persistable implements EncryptableItem {
|
|||
Arrays.fill(mnemonicBytes != null ? mnemonicBytes : new byte[0], (byte)0);
|
||||
|
||||
DeterministicSeed seed = new DeterministicSeed(encryptedMnemonic, needsPassphrase, creationTimeSeconds, type);
|
||||
seed.setId(getId());
|
||||
seed.setPassphrase(passphrase);
|
||||
|
||||
return seed;
|
||||
|
@ -209,6 +210,7 @@ public class DeterministicSeed extends Persistable implements EncryptableItem {
|
|||
KeyDeriver keyDeriver = getEncryptionType().getDeriver().getKeyDeriver(encryptedMnemonicCode.getKeySalt());
|
||||
Key key = keyDeriver.deriveKey(password);
|
||||
DeterministicSeed seed = decrypt(key);
|
||||
seed.setId(getId());
|
||||
key.clear();
|
||||
|
||||
return seed;
|
||||
|
@ -225,6 +227,7 @@ public class DeterministicSeed extends Persistable implements EncryptableItem {
|
|||
Arrays.fill(decrypted, (byte)0);
|
||||
|
||||
DeterministicSeed seed = new DeterministicSeed(mnemonic, needsPassphrase, creationTimeSeconds, type);
|
||||
seed.setId(getId());
|
||||
seed.setPassphrase(passphrase);
|
||||
|
||||
return seed;
|
||||
|
|
|
@ -81,7 +81,10 @@ public class MasterPrivateExtendedKey extends Persistable implements Encryptable
|
|||
EncryptedData encryptedKeyData = keyCrypter.encrypt(secretBytes, null, key);
|
||||
Arrays.fill(secretBytes != null ? secretBytes : new byte[0], (byte)0);
|
||||
|
||||
return new MasterPrivateExtendedKey(encryptedKeyData);
|
||||
MasterPrivateExtendedKey mpek = new MasterPrivateExtendedKey(encryptedKeyData);
|
||||
mpek.setId(getId());
|
||||
|
||||
return mpek;
|
||||
}
|
||||
|
||||
public MasterPrivateExtendedKey decrypt(CharSequence password) {
|
||||
|
@ -91,10 +94,11 @@ public class MasterPrivateExtendedKey extends Persistable implements Encryptable
|
|||
|
||||
KeyDeriver keyDeriver = getEncryptionType().getDeriver().getKeyDeriver(encryptedKey.getKeySalt());
|
||||
Key key = keyDeriver.deriveKey(password);
|
||||
MasterPrivateExtendedKey seed = decrypt(key);
|
||||
MasterPrivateExtendedKey mpek = decrypt(key);
|
||||
mpek.setId(getId());
|
||||
key.clear();
|
||||
|
||||
return seed;
|
||||
return mpek;
|
||||
}
|
||||
|
||||
public MasterPrivateExtendedKey decrypt(Key key) {
|
||||
|
@ -105,7 +109,9 @@ public class MasterPrivateExtendedKey extends Persistable implements Encryptable
|
|||
KeyCrypter keyCrypter = getEncryptionType().getCrypter().getKeyCrypter();
|
||||
byte[] decrypted = keyCrypter.decrypt(encryptedKey, key);
|
||||
try {
|
||||
return new MasterPrivateExtendedKey(Arrays.copyOfRange(decrypted, 0, 32), Arrays.copyOfRange(decrypted, 32, 64));
|
||||
MasterPrivateExtendedKey mpek = new MasterPrivateExtendedKey(Arrays.copyOfRange(decrypted, 0, 32), Arrays.copyOfRange(decrypted, 32, 64));
|
||||
mpek.setId(getId());
|
||||
return mpek;
|
||||
} finally {
|
||||
Arrays.fill(decrypted, (byte)0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue