I'd like to translate the following JS
code into Java
code:
var key = new Bitcoin.ECKey(Crypto.util.hexToBytes(SHA256(password)));
var signed_challenge = Crypto.util.bytesToHex(key.sign(Crypto.util.hexToBytes(SHA256(challenge_key))));
The challenge_key
is the desired output and must be send back to the server.
I'm using bitcoinj
for this. Maybe anyone has already worked with it and can help how the calls in java have to be constructed? I came up with the following, but don't know how to continue:
String password; //the private user pw
String challenge; //a string from the server
BigInteger privkey = new BigInteger(Hex.decode(Sha256Hash.create(password.getBytes()).toString()));
ECKey key = new ECKey(privkey);
key.sign(new Sha256Hash(challenge));
If what I did is correct: how do I get the challange_key out of the ECkey that I signed?