Genera el ECKey

This commit is contained in:
Henry Varona 2016-11-21 16:39:06 -04:30
parent 52c2c9db5e
commit a611f9b388

View file

@ -1,31 +1,30 @@
package com.luminiasoft.bitshares; package com.luminiasoft.bitshares;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
/** /**
* Created by nelson on 11/19/16. * Created by nelson on 11/19/16.
*/ */
public class BrainKey { public class BrainKey {
private ECKey mPrivateKey; private ECKey mPrivateKey;
public BrainKey(String words, int sequence){ public BrainKey(String words, int sequence) {
String encoded = String.format("%s %d", words, sequence); String encoded = String.format("%s %d", words, sequence);
try { try {
MessageDigest md = MessageDigest.getInstance("SHA-512"); MessageDigest md = MessageDigest.getInstance("SHA-512");
byte[] bytes = md.digest(encoded.getBytes("UTF-8")); byte[] bytes = md.digest(encoded.getBytes("UTF-8"));
MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
byte[] result = sha256.digest(bytes); byte[] result = sha256.digest(bytes);
System.out.println("hash: "+Util.bytesToHex(result)); mPrivateKey = ECKey.fromPrivate(result);
//TODO: Transform this final result into a ECKey private key (mPrivateKey) } catch (NoSuchAlgorithmException e) {
} catch (NoSuchAlgorithmException e) { System.out.println("NoSuchAlgotithmException. Msg: " + e.getMessage());
System.out.println("NoSuchAlgotithmException. Msg: "+e.getMessage()); } catch (UnsupportedEncodingException e) {
} catch (UnsupportedEncodingException e) { System.out.println("UnsupportedEncodingException. Msg: " + e.getMessage());
System.out.println("UnsupportedEncodingException. Msg: "+e.getMessage()); }
} }
} }
}