mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 10:06:45 +00:00
wallet encryption and decryption
This commit is contained in:
parent
b951f79cfd
commit
766a986abb
2 changed files with 57 additions and 3 deletions
|
@ -3,9 +3,8 @@ package com.sparrowwallet.drongo.wallet;
|
|||
import com.sparrowwallet.drongo.ExtendedKey;
|
||||
import com.sparrowwallet.drongo.KeyDerivation;
|
||||
import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.crypto.ChildNumber;
|
||||
import com.sparrowwallet.drongo.crypto.DeterministicKey;
|
||||
import com.sparrowwallet.drongo.crypto.HDKeyDerivation;
|
||||
import com.sparrowwallet.drongo.crypto.*;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -146,4 +145,30 @@ public class Keystore {
|
|||
|
||||
return keystore;
|
||||
}
|
||||
|
||||
public boolean isEncrypted() {
|
||||
return seed != null && seed.isEncrypted();
|
||||
}
|
||||
|
||||
public void encrypt(String password) {
|
||||
KeyCrypter keyCrypter = new ScryptKeyCrypter();
|
||||
encrypt(keyCrypter, keyCrypter.deriveKey(password));
|
||||
}
|
||||
|
||||
public void encrypt(KeyCrypter keyCrypter, KeyParameter key) {
|
||||
if(seed != null && !seed.isEncrypted()) {
|
||||
seed = seed.encrypt(keyCrypter, key);
|
||||
}
|
||||
}
|
||||
|
||||
public void decrypt(String password, String passphrase) {
|
||||
KeyCrypter keyCrypter = new ScryptKeyCrypter();
|
||||
decrypt(keyCrypter, passphrase, keyCrypter.deriveKey(password));
|
||||
}
|
||||
|
||||
public void decrypt(KeyCrypter keyCrypter, String passphrase, KeyParameter key) {
|
||||
if(seed != null && seed.isEncrypted()) {
|
||||
seed = seed.decrypt(keyCrypter, passphrase, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package com.sparrowwallet.drongo.wallet;
|
||||
|
||||
import com.sparrowwallet.drongo.crypto.KeyCrypter;
|
||||
import com.sparrowwallet.drongo.crypto.ScryptKeyCrypter;
|
||||
import com.sparrowwallet.drongo.policy.Policy;
|
||||
import com.sparrowwallet.drongo.policy.PolicyType;
|
||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -114,4 +117,30 @@ public class Wallet {
|
|||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
public boolean isEncrypted() {
|
||||
for(Keystore keystore : keystores) {
|
||||
if(keystore.isEncrypted()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void encrypt(String password) {
|
||||
KeyCrypter keyCrypter = new ScryptKeyCrypter();
|
||||
KeyParameter key = keyCrypter.deriveKey(password);
|
||||
for(Keystore keystore : keystores) {
|
||||
keystore.encrypt(keyCrypter, key);
|
||||
}
|
||||
}
|
||||
|
||||
public void decrypt(String password, String passphrase) {
|
||||
KeyCrypter keyCrypter = new ScryptKeyCrypter();
|
||||
KeyParameter key = keyCrypter.deriveKey(password);
|
||||
for(Keystore keystore : keystores) {
|
||||
keystore.decrypt(keyCrypter, passphrase, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue