@@ -887,30 +887,13 @@ public static String getFileContent(File textfile) throws IOException {
887887 public static List <Record > getPrivKeysFromBitcoinJProtobufBackup (InputStream inStream , NetworkParameters network ) throws IOException {
888888 List <Record > returnList = new ArrayList <Record >();
889889 Protos .Wallet wallet = Protos .Wallet .parseFrom (inStream );
890-
891890 for (Protos .Key k : wallet .getKeyList ()) {
892891 byte [] pubKeyBytes = k .getPublicKey ().toByteArray ();
893892 byte [] privKeyBytes = k .getPrivateKey ().toByteArray ();
894-
895- // How does bitcoinj differentiate between compressed and uncompressed keys?
896- // This may not be the best method at all, but we simply try to create first compressed
897- // and then uncompressed keys and check if the resulting public key matches.
898- // Is there a better way to do this?
899-
900- // first try compressed key
901- InMemoryPrivateKey compressedKey = new InMemoryPrivateKey (privKeyBytes , true );
902- if (Arrays .equals (compressedKey .getPublicKey ().getPublicKeyBytes (), pubKeyBytes )) {
903- returnList .add (Record .fromString (compressedKey .getBase58EncodedPrivateKey (network ), network ));
904- continue ;
905- }
906-
907- // if the pubkic key did not match then try uncompressed key
908- InMemoryPrivateKey uncompressedKey = new InMemoryPrivateKey (privKeyBytes , false );
909- if (Arrays .equals (uncompressedKey .getPublicKey ().getPublicKeyBytes (), pubKeyBytes )) {
910- returnList .add (Record .fromString (uncompressedKey .getBase58EncodedPrivateKey (network ), network ));
911- }
893+ boolean keyIsCompressed = (pubKeyBytes .length == 33 );
894+ InMemoryPrivateKey inMemoryKey = new InMemoryPrivateKey (privKeyBytes , keyIsCompressed );
895+ returnList .add (Record .fromString (inMemoryKey .getBase58EncodedPrivateKey (network ), network ));
912896 }
913-
914897 return returnList ;
915898 }
916899
0 commit comments