Bitcoin Forum
December 11, 2016, 06:25:35 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: WIF to address?  (Read 1169 times)
kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
April 10, 2012, 04:30:23 PM
 #1

So, what is the best way to turn a WIF privkey into a public key / address?

Should I convert the WIF to DER or PEM and let openssl make the public key?  Or does anyone have some code that can do it directly?

My target is PHP on Linux, or shell, but I can probably use (or translate) from perl or python.

p2pcoin: a USB/CD/PXE p2pool miner - 1N8ZXx2cuMzqBYSK72X4DAy1UdDbZQNPLf - todo
I routinely ignore posters with paid advertising in their sigs.  You should too.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481437535
Hero Member
*
Offline Offline

Posts: 1481437535

View Profile Personal Message (Offline)

Ignore
1481437535
Reply with quote  #2

1481437535
Report to moderator
1481437535
Hero Member
*
Offline Offline

Posts: 1481437535

View Profile Personal Message (Offline)

Ignore
1481437535
Reply with quote  #2

1481437535
Report to moderator
Ukigo
Hero Member
*****
Offline Offline

Activity: 924


View Profile
April 10, 2012, 05:38:19 PM
 #2

Maybe this thread can help you
https://bitcointalk.org/index.php?topic=23081.0

"...Enemies are everywhere ! Angka is all rage ! Be a good soldiers, blow everything... " <-- Pol Pot (C)
kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
April 10, 2012, 06:13:34 PM
 #3

No, in that thread they are using openSSL to generate the private and public keys as a random pair.  I need to create a public key to match a premade private key.

p2pcoin: a USB/CD/PXE p2pool miner - 1N8ZXx2cuMzqBYSK72X4DAy1UdDbZQNPLf - todo
I routinely ignore posters with paid advertising in their sigs.  You should too.
coretechs
Donator
Sr. Member
*
Offline Offline

Activity: 362



View Profile
April 10, 2012, 06:16:31 PM
 #4

http://bitaddress.org

Wallet Details tab

It runs in the browser (javascript) so you can save a local copy and run it offline for added security.  It supports compressed pubkeys too.  Wink

I know you didn't mention java but bitcoinj is an option too - http://code.google.com/p/bitcoinj/

http://bitcoindoc.com - The Rise and Rise of Bitcoin | http://nxtportal.org - Nxt blockchain explorer
kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
April 10, 2012, 06:39:54 PM
 #5

http://bitaddress.org

Wallet Details tab

It runs in the browser (javascript) so you can save a local copy and run it offline for added security.  It supports compressed pubkeys too.  Wink


Yeah, I've seen that.  Of course, my script doesn't have a browser to paste keys into.  I'm hoping that I don't need to translate that monstrosity myself, but that might just be my next step.

It seems odd that there aren't any command line utilities to package a hex or binary private key into a PEM or DER for openssl to use, and no RPC method to find an address to match an imported key.

p2pcoin: a USB/CD/PXE p2pool miner - 1N8ZXx2cuMzqBYSK72X4DAy1UdDbZQNPLf - todo
I routinely ignore posters with paid advertising in their sigs.  You should too.
kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
April 16, 2012, 04:54:02 AM
 #6

Woohoo.  I got it.  I started with this paper and software and patched it to support the secp256k1 curve.  It is slow as hell, so I think it is doing the multiplication the hard way, but it works.

p2pcoin: a USB/CD/PXE p2pool miner - 1N8ZXx2cuMzqBYSK72X4DAy1UdDbZQNPLf - todo
I routinely ignore posters with paid advertising in their sigs.  You should too.
pointbiz
Sr. Member
****
Offline Offline

Activity: 426

1ninja


View Profile
April 17, 2012, 04:06:26 AM
 #7

http://bitaddress.org

Wallet Details tab

It runs in the browser (javascript) so you can save a local copy and run it offline for added security.  It supports compressed pubkeys too.  Wink


Yeah, I've seen that.  Of course, my script doesn't have a browser to paste keys into.  I'm hoping that I don't need to translate that monstrosity myself, but that might just be my next step.

It seems odd that there aren't any command line utilities to package a hex or binary private key into a PEM or DER for openssl to use, and no RPC method to find an address to match an imported key.

I know you have found a PHP solution but in case others are interested in the javascript command line solution I have provided instructions.

Here is an article on running javascript on the command line:
http://ajaxian.com/archives/javascript-on-the-command-line-or-as-a-shell-scripting-language

You can create a new file called bitaddress.js by copying and pasting the contents of each <script> tag that is inside the <head> of the bitaddress.org HTML document. Only take the JavaScript from the <head> of the document as those are the libraries.

Then at the bottom of that file you can add this function (not tested):
Code:
function wifToAddress(wifKey){
  var bytes = Bitcoin.Base58.decode(wifKey);
  bytes.shift();
  bytes = bytes.slice(0, bytes.length - 4);
  if (bytes.length == 32) {
    var btcKey = new Bitcoin.ECKey(bytes);
    return btcKey.getBitcoinAddress();
  }
}

// call function like this
var myBitcoinAddress = wifToAddress('5ThisIsMyWifAddressLaLaLaLa');

Coder of: https://www.bitaddress.org      Thread
Open Source JavaScript Client-Side Bitcoin Wallet Generator
Donations: 1NiNja1bUmhSoTXozBRBEtR8LeF9TGbZBN   PGP
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!