S
S
SankaSanka2021-03-05 15:53:36
Java
SankaSanka, 2021-03-05 15:53:36

How to get a hash from a string using Java?



I'm trying to implement a string in Java . for example "Vasya!".
at the output I want to get a string like

K21ZG4GJpDjS26p1Ksn3U9JTJJr1Dt3ffwdEZLzjonMoN3AUHtxh
(private key bitcoin)

as far as I figured out this is Hash256.

But when I try to

String sha256hex = org.apache.commons.codec.digest.DigestUtils.sha256Hex("Vasya!");


gives me a string like:

8eef4048cff20030tt08b5b03d237ad829eae0fe880284c6de149800a86a

how can I get the hash type I need from a string?

Thank you very much in advance :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2021-03-05
@2ord

K21ZG4GJpDjS26p1Ksn3U9JTJJr1Dt3ffwdEZLzjonMoN3AUHtxh
is a hash in base 62 (AZ, az, 0-9). How it was obtained, I have no idea. Whether the private key bitcoin was obtained by simply calculating the hash from the string - I don’t know.
When calculating a hash from a string, the md5, sha-1, sha256 or other algorithm is usually taken, depending on the goals. The output will be an array of bits of a fixed length. So, you need to convert it to an array of characters in base 62, where the 0-61th characters will be represented by the alphabet AZ, az, 0-9.

R
rPman, 2021-03-05
@rPman

https://bitcoinj.org/
a bunch of methods for working with bitcoin, incl. with private keys, generation validation, signing lines of text based on the private key of your address, etc.
for example, to sign or verify the signature of a message, you need to use the org.bitcoinj.core.ECKey.signMessage(String message) method after creating the ECKey key

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question