WIF { public static String getWIFFromPrivateKey(byte[] key) { if (key.length != NeoConstants.PRIVATE_KEY_SIZE) { throw new IllegalArgumentException("Given key is not of expected length (" + NeoConstants.PRIVATE_KEY_SIZE + " bytes)."); } byte[] extendenKey = ArrayUtils.concatenate( ArrayUtils.concatenate((byte) 0x80, key), (byte) 0x01); byte[] hash = hash256(extendenKey); byte[] checksum = ArrayUtils.getFirstNBytes(hash, 4); return Base58.encode(ArrayUtils.concatenate(extendenKey, checksum)); }  static byte[] getPrivateKeyFromWIF(String wif); static String getWIFFromPrivateKey(byte[] key);  }
@Test public void privateKeyToWif() { final String privateKey = "9117f4bf9be717c9a90994326897f4243503accd06712162267e77f18b49c3a3"; String result = WIF.getWIFFromPrivateKey(Numeric.hexStringToByteArray(privateKey)); String expected = "L25kgAQJXNHnhc7Sx9bomxxwVSMsZdkaNQ3m2VfHrnLzKWMLP13A"; assertThat(result, is(expected)); }
@Test(expected = IllegalArgumentException.class) public void failUsingWrongSizePrivateKey() { final String privateKey = "9117f4bf9be717c9a90994326897f4243503accd06712162267e77f18b49c3"; WIF.getWIFFromPrivateKey(Numeric.hexStringToByteArray(privateKey)); }