3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Don't abuse BigIntegers in WalletTool/Utils when parsing hex pubkeys.

This commit is contained in:
Mike Hearn 2013-01-08 17:33:19 +01:00
parent ee5f881c51
commit f2a6e41c82
2 changed files with 7 additions and 9 deletions

View File

@ -17,6 +17,7 @@
package com.google.bitcoin.core;
import org.spongycastle.crypto.digests.RIPEMD160Digest;
import org.spongycastle.util.encoders.Hex;
import java.io.IOException;
import java.io.OutputStream;
@ -434,19 +435,17 @@ public class Utils {
* Attempts to parse the given string as arbitrary-length hex or base58 and then return the results, or null if
* neither parse was successful.
*/
public static BigInteger parseAsHexOrBase58(String data) {
BigInteger decode;
public static byte[] parseAsHexOrBase58(String data) {
try {
decode = new BigInteger(data, 16);
return Hex.decode(data);
} catch (Exception e) {
// Didn't decode as hex, try base58.
try {
decode = new BigInteger(1, Base58.decodeChecked(data));
return Base58.decodeChecked(data);
} catch (AddressFormatException e1) {
return null;
}
}
return decode;
}
public static boolean isWindows() {

View File

@ -606,20 +606,19 @@ public class WalletTool {
}
if (options.has("privkey")) {
String data = (String) options.valueOf("privkey");
BigInteger decode = Utils.parseAsHexOrBase58(data);
byte[] decode = Utils.parseAsHexOrBase58(data);
if (decode == null) {
System.err.println("Could not understand --privkey as either hex or base58: " + data);
return;
}
key = new ECKey(decode);
key = new ECKey(new BigInteger(1, decode));
if (options.has("pubkey")) {
// Give the user a hint.
System.out.println("You don't have to specify --pubkey when a private key is supplied.");
}
key.setCreationTimeSeconds(creationTimeSeconds);
} else if (options.has("pubkey")) {
BigInteger decode = Utils.parseAsHexOrBase58((String) options.valueOf("pubkey"));
byte[] pubkey = Utils.bigIntegerToBytes(decode, ECKey.PUBLIC_KEY_LENGTH);
byte[] pubkey = Utils.parseAsHexOrBase58((String) options.valueOf("pubkey"));
key = new ECKey(null, pubkey);
key.setCreationTimeSeconds(creationTimeSeconds);
} else {