@Test(expected = IllegalArgumentException.class) public void testWIF33ByteDifferentThan0x01() { byte[] wifBytes = Base58.decode("L25kgAQJXNHnhc7Sx9bomxxwVSMsZdkaNQ3m2VfHrnLzKWMLP13A"); wifBytes[33] = (byte) 0x00; String wifString = Base58.encode(wifBytes); WIF.getPrivateKeyFromWIF(wifString); }
public static byte[] getPrivateKeyFromWIF(String wif) { if (wif == null) { throw new NullPointerException(); } byte[] data = Base58.decode(wif); if (data.length != 38 || data[0] != (byte) 0x80 || data[33] != 0x01) { throw new IllegalArgumentException("Incorrect WIF format."); } byte[] checksum = hash256(data, 0, data.length - 4); for (int i = 0; i < 4; i++) { if (data[data.length - 4 + i] != checksum[i]) { throw new IllegalArgumentException("Incorrect WIF checksum."); } } byte[] privateKey = new byte[32]; System.arraycopy(data, 1, privateKey, 0, privateKey.length); Arrays.fill(data, (byte) 0); return privateKey; }
WIF { public static byte[] getPrivateKeyFromWIF(String wif) { if (wif == null) { throw new NullPointerException(); } byte[] data = Base58.decode(wif); if (data.length != 38 || data[0] != (byte) 0x80 || data[33] != 0x01) { throw new IllegalArgumentException("Incorrect WIF format."); } byte[] checksum = hash256(data, 0, data.length - 4); for (int i = 0; i < 4; i++) { if (data[data.length - 4 + i] != checksum[i]) { throw new IllegalArgumentException("Incorrect WIF checksum."); } } byte[] privateKey = new byte[32]; System.arraycopy(data, 1, privateKey, 0, privateKey.length); Arrays.fill(data, (byte) 0); return privateKey; } }
WIF { public static byte[] getPrivateKeyFromWIF(String wif) { if (wif == null) { throw new NullPointerException(); } byte[] data = Base58.decode(wif); if (data.length != 38 || data[0] != (byte) 0x80 || data[33] != 0x01) { throw new IllegalArgumentException("Incorrect WIF format."); } byte[] checksum = hash256(data, 0, data.length - 4); for (int i = 0; i < 4; i++) { if (data[data.length - 4 + i] != checksum[i]) { throw new IllegalArgumentException("Incorrect WIF checksum."); } } byte[] privateKey = new byte[32]; System.arraycopy(data, 1, privateKey, 0, privateKey.length); Arrays.fill(data, (byte) 0); return privateKey; }  }
WIF { public static byte[] getPrivateKeyFromWIF(String wif) { if (wif == null) { throw new NullPointerException(); } byte[] data = Base58.decode(wif); if (data.length != 38 || data[0] != (byte) 0x80 || data[33] != 0x01) { throw new IllegalArgumentException("Incorrect WIF format."); } byte[] checksum = hash256(data, 0, data.length - 4); for (int i = 0; i < 4; i++) { if (data[data.length - 4 + i] != checksum[i]) { throw new IllegalArgumentException("Incorrect WIF checksum."); } } byte[] privateKey = new byte[32]; System.arraycopy(data, 1, privateKey, 0, privateKey.length); Arrays.fill(data, (byte) 0); return privateKey; }  static byte[] getPrivateKeyFromWIF(String wif); static String getWIFFromPrivateKey(byte[] key); }
WIF { public static byte[] getPrivateKeyFromWIF(String wif) { if (wif == null) { throw new NullPointerException(); } byte[] data = Base58.decode(wif); if (data.length != 38 || data[0] != (byte) 0x80 || data[33] != 0x01) { throw new IllegalArgumentException("Incorrect WIF format."); } byte[] checksum = hash256(data, 0, data.length - 4); for (int i = 0; i < 4; i++) { if (data[data.length - 4 + i] != checksum[i]) { throw new IllegalArgumentException("Incorrect WIF checksum."); } } byte[] privateKey = new byte[32]; System.arraycopy(data, 1, privateKey, 0, privateKey.length); Arrays.fill(data, (byte) 0); return privateKey; }  static byte[] getPrivateKeyFromWIF(String wif); static String getWIFFromPrivateKey(byte[] key);  }