byte[] hashBytes = Bytes.concat(passFactorBytes, ownerEntropy); checkState(hashBytes.length == 40); passFactorBytes = Sha256Hash.createDouble(hashBytes).getBytes(); BigInteger seedFactor = new BigInteger(1, Sha256Hash.createDouble(seed).getBytes()); checkState(passFactor.signum() >= 0); checkState(seedFactor.signum() >= 0);
byte[] hashBytes = Bytes.concat(passFactorBytes, ownerEntropy); checkState(hashBytes.length == 40); passFactorBytes = Sha256Hash.createDouble(hashBytes).getBytes(); BigInteger seedFactor = new BigInteger(1, Sha256Hash.createDouble(seed).getBytes()); checkState(passFactor.signum() >= 0); checkState(seedFactor.signum() >= 0);
public TypedKey decryptBip38(String passphrase) throws BadPassphraseException { String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC); ECKey key = ecMultiply ? decryptBip38EC(normalizedPassphrase) : decryptBip38NoEC(normalizedPassphrase); String address = null; for (CoinType type : CoinID.getSupportedCoins()) { String possibleAddress = key.toAddress(type).toString(); Sha256Hash hash = Sha256Hash.createDouble(possibleAddress.getBytes(Charsets.US_ASCII)); byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4); if (Arrays.equals(actualAddressHash, addressHash)) { address = possibleAddress; } } if (address == null) { throw new BadPassphraseException(); } try { return new TypedKey(GenericUtils.getPossibleTypes(address), key); } catch (AddressMalformedException e) { throw new RuntimeException(e); // Should not happen } }
public TypedKey decryptBip38(String passphrase) throws BadPassphraseException { String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC); ECKey key = ecMultiply ? decryptBip38EC(normalizedPassphrase) : decryptBip38NoEC(normalizedPassphrase); String address = null; for (CoinType type : CoinID.getSupportedCoins()) { String possibleAddress = key.toAddress(type).toString(); Sha256Hash hash = Sha256Hash.createDouble(possibleAddress.getBytes(Charsets.US_ASCII)); byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4); if (Arrays.equals(actualAddressHash, addressHash)) { address = possibleAddress; } } if (address == null) { throw new BadPassphraseException(); } try { return new TypedKey(GenericUtils.getPossibleTypes(address), key); } catch (AddressMalformedException e) { throw new RuntimeException(e); // Should not happen } }