Bitcoin Forum
May 27, 2024, 03:11:58 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to authenticate with challange and private keys? [Java]  (Read 1386 times)
membersound (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
February 13, 2014, 04:22:24 PM
 #1

I'd like to translate the following JS code into Java code:

Code:
var key = new Bitcoin.ECKey(Crypto.util.hexToBytes(SHA256(password))); //password = private user password
var signed_challenge = Crypto.util.bytesToHex(key.sign(Crypto.util.hexToBytes(SHA256(challenge_key)))); //challenge_key = generated key from server
The challenge_key is the desired output and must be send back to the server.

I'm want to use 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:
Code:
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 that has to be send back to the server out of the ECkey that I signed?
Mike Hearn
Moderator
Legendary
*
Offline Offline

Activity: 1526
Merit: 1129


View Profile
March 03, 2014, 11:27:09 PM
 #2

key.sign returns an object with the r/s components in it. You can send them back to the server.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!