mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
minor additions to support bip129
This commit is contained in:
parent
50fdb71bf3
commit
caed93ca6d
2 changed files with 17 additions and 1 deletions
|
@ -23,6 +23,7 @@ public class Utils {
|
|||
|
||||
public static final String HEX_REGEX = "^[0-9A-Fa-f]+$";
|
||||
public static final String BASE64_REGEX = "^[0-9A-Za-z\\\\+=/]+$";
|
||||
public static final String NUMERIC_REGEX = "^-?\\d+(\\.\\d+)?$";
|
||||
|
||||
public static boolean isHex(String s) {
|
||||
return s.matches(HEX_REGEX);
|
||||
|
@ -32,6 +33,10 @@ public class Utils {
|
|||
return s.matches(BASE64_REGEX);
|
||||
}
|
||||
|
||||
public static boolean isNumber(String s) {
|
||||
return s.matches(NUMERIC_REGEX);
|
||||
}
|
||||
|
||||
public static boolean isUtf8(byte[] bytes) {
|
||||
try {
|
||||
CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder();
|
||||
|
|
|
@ -7,25 +7,36 @@ import org.bouncycastle.crypto.params.KeyParameter;
|
|||
|
||||
public class Pbkdf2KeyDeriver implements KeyDeriver, AsymmetricKeyDeriver {
|
||||
public static final int DEFAULT_ITERATION_COUNT = 1024;
|
||||
public static final int DEFAULT_KEY_SIZE = 512;
|
||||
|
||||
private final byte[] salt;
|
||||
private final int iterationCount;
|
||||
private final int keySize;
|
||||
|
||||
public static final Pbkdf2KeyDeriver DEFAULT_INSTANCE = new Pbkdf2KeyDeriver();
|
||||
|
||||
public Pbkdf2KeyDeriver() {
|
||||
this.salt = new byte[0];
|
||||
this.iterationCount = DEFAULT_ITERATION_COUNT;
|
||||
this.keySize = DEFAULT_KEY_SIZE;
|
||||
}
|
||||
|
||||
public Pbkdf2KeyDeriver(byte[] salt) {
|
||||
this.salt = salt;
|
||||
this.iterationCount = DEFAULT_ITERATION_COUNT;
|
||||
this.keySize = DEFAULT_KEY_SIZE;
|
||||
}
|
||||
|
||||
public Pbkdf2KeyDeriver(byte[] salt, int iterationCount) {
|
||||
this.salt = salt;
|
||||
this.iterationCount = iterationCount;
|
||||
this.keySize = DEFAULT_KEY_SIZE;
|
||||
}
|
||||
|
||||
public Pbkdf2KeyDeriver(byte[] salt, int iterationCount, int keySize) {
|
||||
this.salt = salt;
|
||||
this.iterationCount = iterationCount;
|
||||
this.keySize = keySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,7 +48,7 @@ public class Pbkdf2KeyDeriver implements KeyDeriver, AsymmetricKeyDeriver {
|
|||
public Key deriveKey(CharSequence password) throws KeyCrypterException {
|
||||
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA512Digest());
|
||||
gen.init(SecureString.toBytesUTF8(password), salt, iterationCount);
|
||||
byte[] keyBytes = ((KeyParameter)gen.generateDerivedParameters(512)).getKey();
|
||||
byte[] keyBytes = ((KeyParameter)gen.generateDerivedParameters(keySize)).getKey();
|
||||
return new Key(keyBytes, salt, getDeriverType());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue