MultiChainAddressGenerator { public static String getPublicAddress(String[] version, String addressChecksum, byte[] pubKey) { MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); digest.reset(); byte[] hash = digest.digest(pubKey); RIPEMD160Digest ripemd = new RIPEMD160Digest(); ripemd.update(hash, 0, hash.length); byte[] out = new byte[20]; ripemd.doFinal(out, 0); String hashStr = Util.byteArrayToHexString(out); String step5 = ""; if (BuildConfig.DEBUG && version.length != 4) throw new AssertionError("Version length != 4"); for (int i = 0; i < 4; i++) { step5 += version[i] + hashStr.substring((i*10),(i*10)+10); } digest.reset(); byte[] step6 = digest.digest(Util.hexStringToByteArray(step5)); digest.reset(); byte[] step7 = digest.digest(step6); digest.reset(); byte[] checksum = new byte[]{ step7[0],step7[1],step7[2],step7[3] }; byte[] byteAddressChecksum = Util.hexStringToByteArray(addressChecksum); byte[] xor = new byte[4]; for (int i = 0; i < 4; i++) { int xorvalue = (int)checksum[i] ^ (int)byteAddressChecksum[i]; xor[i] = (byte)(0xff & xorvalue); } String addressbytes = step5 + Util.byteArrayToHexString(xor); String address = Base58.encode(Util.hexStringToByteArray(addressbytes)); return address; } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); return null; } }  static String getPublicAddress(String[] version, String addressChecksum, byte[] pubKey); static String getPublicAddress(String[] version, String addressChecksum, PublicKey pubKey);  }
@Test public void testGetAddress() throws Exception { String[] version = new String[]{"00", "AF", "EA", "21"}; String addresschecksum = "953ABC69"; MultiChainAddressGenerator generator = new MultiChainAddressGenerator(); String pubKey = "0284E5235E299AF81EBE1653AC5F06B60E13A3A81F918018CBD10CE695095B3E24"; byte[] keybytes = Util.hexStringToByteArray(pubKey); String address = generator.getPublicAddress(version, addresschecksum, keybytes); assertEquals(address, "1Yu2BuptuZSiBWfr2Qy4aic6qEVnwPWrdkHPEc"); }
@Test public void testGetAddress2() throws Exception { String[] version = new String[]{ "00", "8c", "b5", "d6"}; String addresschecksum = "5afce7b2"; MultiChainAddressGenerator generator = new MultiChainAddressGenerator(); String pubKey = "6c284c42d95e4933513d663a8a2e4cf0e41bcb7f8397bd065e6e3f2d4176e95f66c317bf612bec0207f3954783fd361a71118eea680655607953a1aceddf045c7133e99f35a9391c5c28d5d82c12b148"; byte[] keybytes = Util.hexStringToByteArray(pubKey); String address = generator.getPublicAddress(version, addresschecksum, keybytes); assertEquals(address, "1BNgsh92p1wFmKiQVPs9fNyriG72wygs9esHV8"); }