如何通过质询和私钥进行身份验证?

时间:2014-02-13 15:08:44

标签: java javascript bitcoinj

我想将以下JS代码翻译成Java代码:

var key = new Bitcoin.ECKey(Crypto.util.hexToBytes(SHA256(password)));
var signed_challenge = Crypto.util.bytesToHex(key.sign(Crypto.util.hexToBytes(SHA256(challenge_key))));

challenge_key是所需的输出,必须发送回服务器。

我正在使用bitcoinj。也许任何人已经使用它并且可以帮助如何构建java中的调用?我想出了以下内容,但不知道如何继续:

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));

如果我所做的是正确的:如何从我签署的ECkey中获取challange_key?

0 个答案:

没有答案