@Test public void testParse(){ BackupUtil util = new BackupUtil(ENCRYPTED_KEY, CORRECT_PASSWORD); String decoded = util.getKey(); assertEquals(EXPECTED_RESPONSE, decoded); decoded= new BackupUtil(ENCRYPTED_KEY, "QDTDXOYFBXBKKMK").getKey(); assertEquals(EXPECTED_RESPONSE, decoded); }
public String getKey() { final String realpassword; if (password.length() == 16) { boolean checksumValid = MrdExport.isChecksumValid(password); if (!checksumValid) { return "Error: the last character of the password was not matching the checksum"; } else { realpassword = password.substring(0, 15); } } else { if (password.length() != 15) { return "Error: the supplied password did not match the expected length"; } realpassword = password; } try { MrdExport.V1.Header header = MrdExport.V1.extractHeader(encryptedPrivateKey); MrdExport.V1.KdfParameters kdfParameters = MrdExport.V1.KdfParameters.fromPassphraseAndHeader(realpassword, header); MrdExport.V1.EncryptionParameters parameters = MrdExport.V1.EncryptionParameters.generate(kdfParameters); String privateKey = MrdExport.V1.decryptPrivateKey(parameters, encryptedPrivateKey, header.network); InMemoryPrivateKey key = new InMemoryPrivateKey(privateKey, header.network); return "Private key (Wallet Import Format): " + key.getBase58EncodedPrivateKey(header.network) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2PKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2SH_P2WPKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2WPKH); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (MrdExport.V1.WrongNetworkException e) { throw new RuntimeException(e); } catch (MrdExport.V1.InvalidChecksumException e) { return "Error: the supplied password did not match the checksum of the encrypted key"; } catch (MrdExport.DecodingException e) { throw new RuntimeException(e); } }
BackupUtil { public String getKey() { final String realpassword; if (password.length() == 16) { boolean checksumValid = MrdExport.isChecksumValid(password); if (!checksumValid) { return "Error: the last character of the password was not matching the checksum"; } else { realpassword = password.substring(0, 15); } } else { if (password.length() != 15) { return "Error: the supplied password did not match the expected length"; } realpassword = password; } try { MrdExport.V1.Header header = MrdExport.V1.extractHeader(encryptedPrivateKey); MrdExport.V1.KdfParameters kdfParameters = MrdExport.V1.KdfParameters.fromPassphraseAndHeader(realpassword, header); MrdExport.V1.EncryptionParameters parameters = MrdExport.V1.EncryptionParameters.generate(kdfParameters); String privateKey = MrdExport.V1.decryptPrivateKey(parameters, encryptedPrivateKey, header.network); InMemoryPrivateKey key = new InMemoryPrivateKey(privateKey, header.network); return "Private key (Wallet Import Format): " + key.getBase58EncodedPrivateKey(header.network) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2PKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2SH_P2WPKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2WPKH); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (MrdExport.V1.WrongNetworkException e) { throw new RuntimeException(e); } catch (MrdExport.V1.InvalidChecksumException e) { return "Error: the supplied password did not match the checksum of the encrypted key"; } catch (MrdExport.DecodingException e) { throw new RuntimeException(e); } } }
BackupUtil { public String getKey() { final String realpassword; if (password.length() == 16) { boolean checksumValid = MrdExport.isChecksumValid(password); if (!checksumValid) { return "Error: the last character of the password was not matching the checksum"; } else { realpassword = password.substring(0, 15); } } else { if (password.length() != 15) { return "Error: the supplied password did not match the expected length"; } realpassword = password; } try { MrdExport.V1.Header header = MrdExport.V1.extractHeader(encryptedPrivateKey); MrdExport.V1.KdfParameters kdfParameters = MrdExport.V1.KdfParameters.fromPassphraseAndHeader(realpassword, header); MrdExport.V1.EncryptionParameters parameters = MrdExport.V1.EncryptionParameters.generate(kdfParameters); String privateKey = MrdExport.V1.decryptPrivateKey(parameters, encryptedPrivateKey, header.network); InMemoryPrivateKey key = new InMemoryPrivateKey(privateKey, header.network); return "Private key (Wallet Import Format): " + key.getBase58EncodedPrivateKey(header.network) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2PKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2SH_P2WPKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2WPKH); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (MrdExport.V1.WrongNetworkException e) { throw new RuntimeException(e); } catch (MrdExport.V1.InvalidChecksumException e) { return "Error: the supplied password did not match the checksum of the encrypted key"; } catch (MrdExport.DecodingException e) { throw new RuntimeException(e); } } BackupUtil(String... args); }
BackupUtil { public String getKey() { final String realpassword; if (password.length() == 16) { boolean checksumValid = MrdExport.isChecksumValid(password); if (!checksumValid) { return "Error: the last character of the password was not matching the checksum"; } else { realpassword = password.substring(0, 15); } } else { if (password.length() != 15) { return "Error: the supplied password did not match the expected length"; } realpassword = password; } try { MrdExport.V1.Header header = MrdExport.V1.extractHeader(encryptedPrivateKey); MrdExport.V1.KdfParameters kdfParameters = MrdExport.V1.KdfParameters.fromPassphraseAndHeader(realpassword, header); MrdExport.V1.EncryptionParameters parameters = MrdExport.V1.EncryptionParameters.generate(kdfParameters); String privateKey = MrdExport.V1.decryptPrivateKey(parameters, encryptedPrivateKey, header.network); InMemoryPrivateKey key = new InMemoryPrivateKey(privateKey, header.network); return "Private key (Wallet Import Format): " + key.getBase58EncodedPrivateKey(header.network) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2PKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2SH_P2WPKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2WPKH); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (MrdExport.V1.WrongNetworkException e) { throw new RuntimeException(e); } catch (MrdExport.V1.InvalidChecksumException e) { return "Error: the supplied password did not match the checksum of the encrypted key"; } catch (MrdExport.DecodingException e) { throw new RuntimeException(e); } } BackupUtil(String... args); static void main(String[] args); String getKey(); }
BackupUtil { public String getKey() { final String realpassword; if (password.length() == 16) { boolean checksumValid = MrdExport.isChecksumValid(password); if (!checksumValid) { return "Error: the last character of the password was not matching the checksum"; } else { realpassword = password.substring(0, 15); } } else { if (password.length() != 15) { return "Error: the supplied password did not match the expected length"; } realpassword = password; } try { MrdExport.V1.Header header = MrdExport.V1.extractHeader(encryptedPrivateKey); MrdExport.V1.KdfParameters kdfParameters = MrdExport.V1.KdfParameters.fromPassphraseAndHeader(realpassword, header); MrdExport.V1.EncryptionParameters parameters = MrdExport.V1.EncryptionParameters.generate(kdfParameters); String privateKey = MrdExport.V1.decryptPrivateKey(parameters, encryptedPrivateKey, header.network); InMemoryPrivateKey key = new InMemoryPrivateKey(privateKey, header.network); return "Private key (Wallet Import Format): " + key.getBase58EncodedPrivateKey(header.network) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2PKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2SH_P2WPKH) + "\n Bitcoin Address: " + key.getPublicKey().toAddress(header.network, AddressType.P2WPKH); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (MrdExport.V1.WrongNetworkException e) { throw new RuntimeException(e); } catch (MrdExport.V1.InvalidChecksumException e) { return "Error: the supplied password did not match the checksum of the encrypted key"; } catch (MrdExport.DecodingException e) { throw new RuntimeException(e); } } BackupUtil(String... args); static void main(String[] args); String getKey();  }