本文整理汇总了Java中org.bitcoinj.core.Base58.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base58.encode方法的具体用法?Java Base58.encode怎么用?Java Base58.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.Base58
的用法示例。
在下文中一共展示了Base58.encode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deriveSIN
import org.bitcoinj.core.Base58; //导入方法依赖的package包/类
public static String deriveSIN(ECKey ecKey) throws IllegalArgumentException {
// Get sha256 hash and then the RIPEMD-160 hash of the public key (this call gets the result in one step).
byte[] pubKeyHash = ecKey.getPubKeyHash();
// Convert binary pubKeyHash, SINtype and version to Hex
String version = "0F";
String SINtype = "02";
String pubKeyHashHex = bytesToHex(pubKeyHash);
// Concatenate all three elements
String preSIN = version + SINtype + pubKeyHashHex;
// Convert the hex string back to binary and double sha256 hash it leaving in binary both times
byte[] preSINbyte = hexToBytes(preSIN);
byte[] hash2Bytes = Sha256Hash.hashTwice(preSINbyte);
// Convert back to hex and take first four bytes
String hashString = bytesToHex(hash2Bytes);
String first4Bytes = hashString.substring(0, 8);
// Append first four bytes to fully appended SIN string
String unencoded = preSIN + first4Bytes;
byte[] unencodedBytes = new BigInteger(unencoded, 16).toByteArray();
return Base58.encode(unencodedBytes);
}
示例2: encodeWithChecksum
import org.bitcoinj.core.Base58; //导入方法依赖的package包/类
/**
* Base58Checksum Util
*
* @param b
* @return
*/
private String encodeWithChecksum(byte[] base58Bytes){
//String strBase58Encoded = Base58.encode(b);
//byte[] base58Bytes = strBase58Encoded.getBytes();
byte[] checksum = copyOfRange(Utils.doubleDigest(base58Bytes), 0, 4);
// append
byte[] base58Checksum = new byte[base58Bytes.length + checksum.length];
System.arraycopy(base58Bytes, 0, base58Checksum, 0, base58Bytes.length);
System.arraycopy(checksum, 0, base58Checksum, base58Bytes.length, checksum.length);
//
return Base58.encode(base58Checksum);//new String(base58Checksum);
}
示例3: getPublicAddress
import org.bitcoinj.core.Base58; //导入方法依赖的package包/类
/**
* Converts a given public key to a valid MultiChain address.
* See {@link <a href="http://www.multichain.com/developers/address-key-format/">MultiChain Documentation</a>}
* @param pubKey byte array containing the public key
* @return String representing the corresponding address.
*/
public static String getPublicAddress(String[] version, String addressChecksum, byte[] pubKey) {
//Step 3
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-256");
digest.reset();
byte[] hash = digest.digest(pubKey);
//Step 4
RIPEMD160Digest ripemd = new RIPEMD160Digest();
ripemd.update(hash, 0, hash.length);
byte[] out = new byte[20];
ripemd.doFinal(out, 0);
String hashStr = Util.byteArrayToHexString(out);
//Step 5
String step5 = "";
if (BuildConfig.DEBUG && version.length != 4) throw new AssertionError("Version length != 4");
for (int i = 0; i < 4; i++) { //Assumes version.length == 4
step5 += version[i] + hashStr.substring((i*10),(i*10)+10);
}
digest.reset();
//Step 6
byte[] step6 = digest.digest(Util.hexStringToByteArray(step5));
digest.reset();
//Step 7
byte[] step7 = digest.digest(step6);
digest.reset();
//Step 8
byte[] checksum = new byte[]{ step7[0],step7[1],step7[2],step7[3] };
//Step 9
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);
}
//Step 10
String addressbytes = step5 + Util.byteArrayToHexString(xor);
//Step 11
String address = Base58.encode(Util.hexStringToByteArray(addressbytes));
return address;
} catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
return null;
}
}