Bitcoin/public point to address: Difference between revisions

Content deleted Content added
PSNOW123 (talk | contribs)
New post.
PSNOW123 (talk | contribs)
m Improved coding.
Line 620:
<syntaxhighlight lang="java">
import java.math.BigInteger;
import java.nio.ByteBuffercharset.StandardCharsets;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
public final class BitcoinPublicPointToAddess {
Line 687 ⟶ 686:
// Convert the hexadecimal string 'text' into a suitable ASCII string for the SHA256 hash
byte[] bytesOne = hexToBytes(text);
String asciiOne = bytesToASCIIStringnew String(bytesOne, StandardCharsets.ISO_8859_1);
String hexSHA256 = SHA256.messageDigest(asciiOne);
// Convert the hexadecimal string 'hexSHA256' into a suitable ASCII string for the RIPEMD160 hash
byte[] bytesTwo = hexToBytes(hexSHA256);
String asciiTwo = bytesToASCIIStringnew String(bytesTwo, StandardCharsets.ISO_8859_1);
String hexRIPEMD160 = RIPEMD160.messageDigest(asciiTwo);
hexRIPEMD160 = BITCOIN_VERSION_NUMBER + hexRIPEMD160;
Line 699 ⟶ 698:
private static byte[] computeChecksum(byte[] bytes) {
// Convert the given byte array into a suitable ASCII string for the first SHA256 hash
String ascii1asciiOne = bytesToASCIIStringnew String(bytes, StandardCharsets.ISO_8859_1);
String hex1hexOne = SHA256.messageDigest(ascii1asciiOne);
// Convert the hexadecimal string 'hex1' into a suitable ASCII string for the second SHA256 hash
byte[] bytes1bytesOne = hexToBytes(hex1hexOne);
String ascii2asciiTwo = bytesToASCIIStringnew String(bytes1bytesOne, StandardCharsets.ISO_8859_1);
String hex2hexTwo = SHA256.messageDigest(ascii2asciiTwo);
return Arrays.copyOfRange(hexToBytes(hex2hexTwo), 0, 4);
}
Line 716 ⟶ 715:
}
return bytes;
}
 
private static String bytesToASCIIString(byte[] hash) {
ByteBuffer buffer = ByteBuffer.wrap(hash);
return Stream.generate( () -> buffer.get() ).limit(buffer.capacity())
.map( bb -> String.valueOf((char) ( bb & 0xFF )) ).collect(Collectors.joining(""));
}