按照比特币协议文档上描述,scriptPubKey的格式如下(https://en.bitcoin.it/wiki/Script)
Standard Transaction to Bitcoin address (pay-to-pubkey-hash)
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>
《精通比特币》第四章中描述pubKeyHash的计算方式如下:
pubKeyHash:A = RIPEMD160(SHA256(K)) //K是公钥 A:未Base58处理的Address
而Address : Base58(version + A + checksum) //Base58之后的Address
那么可以由Address推算出pubKeyHash
bither-android/bitherj/bitherj/src/main/java/net/bither/bitherj/utils/Utils.java
public static byte[] getAddressHash(String address) throws AddressFormatException {
byte[] tmp = Base58.decodeChecked(address);
byte[] bytes = new byte[tmp.length - 1];
System.arraycopy(tmp, 1, bytes, 0, tmp.length - 1);
return bytes;
}