Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: hamdi on March 12, 2012, 08:05:40 AM



Title: create btc-address + key in only PHP ?
Post by: hamdi on March 12, 2012, 08:05:40 AM
hi.

how can i generate a valid address + key in PHP without any extra tools?

so that i can save the adress+key on the server and later import these into "Armory"

i want a website to receive BTC without actually steadily connecting to a bitcoind.

thanks for any directions!


Title: Re: create btc-address + key in only PHP ?
Post by: BurtW on March 12, 2012, 08:22:43 AM
You can generate as many key pairs as your heart desires at https://www.bitaddress.org

You can download the script and run it on a computer totally disconnected from the internet.

It will also print out the key pairs to create paper wallets.


Title: Re: create btc-address + key in only PHP ?
Post by: ThomasV on March 12, 2012, 09:12:40 AM
hi.

how can i generate a valid address + key in PHP without any extra tools?

so that i can save the adress+key on the server and later import these into "Armory"

i want a website to receive BTC without actually steadily connecting to a bitcoind.

thanks for any directions!

you should not generate private keys on your server, that's not safe.
with Electrum, you can generate new Bitcoin addresses without storing private keys on your server.
This is possible because it uses a "type 2" deterministic wallet, where all your addresses are generated from a public master key.
if an attacker get access to the public master key, they can know the addresses that you use, but they cannot steal your coins.
see this demo: http://ecdsa.org/remote.php






Title: Re: create btc-address + key in only PHP ?
Post by: hamdi on March 15, 2012, 11:50:47 PM
thanks you all!


Title: Re: create btc-address + key in only PHP ?
Post by: cjp on March 16, 2012, 05:48:26 PM
I'd also advice against keeping private keys on your server. Your server is online 24h/day, and it is probably visible that it's doing something with Bitcoin, so it's an obviously attractive target for hackers.

So: just generate your key pairs on a different computer (in advance), and save only the public part (the Bitcoin address) on the server.

I did it this way, on the donation page of my website:
http://www.ultimatestunts.nl/index.php?page=12 (http://www.ultimatestunts.nl/index.php?page=12)

Please note that my website appears to have functionality that creates new addresses. This is fake: in reality, these "new" addresses are already present on the server (only the public part, as I adviced). I just have a pre-calculated pool of addresses, and whenever the server needs a new address, it takes a new one from the pool.

Maybe that's also an interesting option for you.


Title: Re: create btc-address + key in only PHP ?
Post by: hamdi on May 12, 2012, 06:26:59 PM
i still want to create the addresses via PHP

i would create the address and send the private key to another server.


is there an example how to create a valid btc address + private key in php?

basically i just want what www.bitaddress.org īs javascript does in php.


Title: Re: create btc-address + key in only PHP ?
Post by: kjj on May 21, 2012, 05:45:14 AM
I got it working.  You need a library for EC math and the curve definition for SEC p256k1.

You generate the private key yourself, and converting it to a WIF is pretty simple.  To get the public key, you multiply G (the generator from the p256k1 curve) by the private key.  From there, creating an address is simple too.

I'm using the LGPL ECC library from Matyas Danter, but it took some effort.


Title: Re: create btc-address + key in only PHP ?
Post by: Realpra on June 04, 2012, 08:43:48 AM
* So if I download that HTML/javascript code here www.bitaddress.org, it will work yes?
   (Did a quick test myself, just wondering if it is also working correctly)

* Has someone extensively tested that these addresses work and are not sent to the operator of that site or some hardware disc location?

* Say someone makes a bad script is it possible to create non-valid addresses/key pairs (ie if I transfer money there they get locked
  forever).
   Can I test addresses somehow?

* Is the script dependent on your OS and java updates, could it fail if run on a clean Ubuntu install?

I ask all of this as I am about to transfer a decent pile of cash to addresses I want to generate offline on a live cd running Ubuntu.


Title: Re: create btc-address + key in only PHP ?
Post by: weex on June 04, 2012, 10:01:18 AM
* So if I download that HTML/javascript code here www.bitaddress.org, it will work yes?
   (Did a quick test myself, just wondering if it is also working correctly)
I have used this method to generate addresses so I think it's reasonable. I actually used vanitygen to generate addresses and modified the code to accept my private key. The current version of bitaddress.org actually accepts private keys but I can't say it did when I worked on it. What's nice is the private key vanitygen gives you yields the same address on bitaddress.org as shown by vanitygen. You could use this as a way to double check.
Quote
* Has someone extensively tested that these addresses work and are not sent to the operator of that site or some hardware disc location?
You can go offline after downloading the web page but for the super-paranoid you want to be mindful of a couple of possibilities.
Someone could hack bitaddress.org and place their own malicious code there that:
   a) generates bad addresses
   b) sends them to a server
   c) instead generates them all from a seed that is stored by a server.
Quote
* Say someone makes a bad script is it possible to create non-valid addresses/key pairs (ie if I transfer money there they get locked
  forever).
   Can I test addresses somehow?
You can test this process by generating an address however you want to and sending 0.01 BTC to it. Then creating a new wallet at blockchain.info and importing the private key into that My Wallet. Finally, send the coins back to a known-good address of yours. If the transactions is confirmed, your process works (barring security concerns).
Quote
* Is the script dependable on your OS and java updates, could it fail if run on a clean Ubuntu install?

I ask all of this as I am about to transfer a decent pile of cash to addresses I want to generate offline on a live cd running Ubuntu.
I guess you mean dependent. Every script needs some sort of environment in which to run. PHP can be made pretty well machine independent. Python too. I'm actually looking at trimming down pywallet.py to create a utility that has the minimum amount of code required to generate a new address and private key and print them to the screen.


Title: Re: create btc-address + key in only PHP ?
Post by: Realpra on June 06, 2012, 01:46:35 PM
Thanks.

Yes I meant dependent.

I suppose I can look through the code for how its seeded.

I'll report back if I find anything suspicious.


Title: Re: create btc-address + key in only PHP ?
Post by: weex on June 06, 2012, 04:03:56 PM
Ok, in case it is of use to anyone, I have gotten some help from Joric to create a script that generates keys in only python. This could be called from your PHP. Inside it supports generating keys from a passphrase or from a known private key and more.

https://github.com/weex/addrgen


Title: Re: create btc-address + key in only PHP ?
Post by: dooglus on June 06, 2012, 08:15:31 PM
Ok, in case it is of use to anyone, I have gotten some help from Joric to create a script that generates keys in only python. This could be called from your PHP. Inside it supports generating keys from a passphrase or from a known private key and more.

https://github.com/weex/addrgen

Very nice, thanks.

If you're aiming for minimal, none of set_privkey(), set_pubkey(), get_privkey() seem to be used at all.


Title: Re: create btc-address + key in only PHP ?
Post by: weex on June 06, 2012, 10:37:10 PM
If you're aiming for minimal, none of set_privkey(), set_pubkey(), get_privkey() seem to be used at all.

Thanks, removed.


Title: Re: create btc-address + key in only PHP ?
Post by: Stephen Gornick on June 15, 2012, 09:21:23 AM
One other PHP library mentioned here:
 - http://bitcoin.stackexchange.com/a/2488/153


Title: Re: create btc-address + key in only PHP ?
Post by: kjj on August 31, 2012, 03:26:37 PM
http://matejdanter.com/2010/12/elliptic-curve-php-oop-dsa-and-diffie-hellman/ (http://matejdanter.com/2010/12/elliptic-curve-php-oop-dsa-and-diffie-hellman/)

Library download link at the bottom.  You need to add a generator for secp256k1.


Title: Re: create btc-address + key in only PHP ?
Post by: bitfreak! on September 08, 2012, 08:08:12 PM
Bitcoin SCI (PHP): process transactions yourself! (https://bitcointalk.org/index.php?topic=56801.msg1131265)

That project contains all the tools necessary for generating bitcoin addresses with only PHP. It started as a simple effort to generate new bitcoin addresses in PHP but I decided to go that extra step and create a sort of private bitcoin payment gateway. It allows for generation of new addresses and confirmation of bitcoin transactions without having bitcoind installed on the server.

Or to provide a potentially simpler alternative solution, there's also the PHP Bitcoin Address Creator (https://github.com/RobKohr/PHP-Bitcoin-Address-Creator) which is PHP script designed to execute a variant of the bitcoin-off-the-grid (https://bitcointalk.org/index.php?topic=23081.20) bash script. However the bash script has multiple dependencies so it's not exactly plug-and-play in all cases, and that's why I opted to design a pure PHP solution.


Title: Re: create btc-address + key in only PHP ?
Post by: scintill on September 08, 2012, 09:40:57 PM
Bitcoin SCI (PHP): process transactions yourself! (https://bitcointalk.org/index.php?topic=56801.msg1131265)

That project contains all the tools necessary for generating bitcoin addresses with only PHP. It started as a simple effort to generate new bitcoin addresses in PHP but I decided to go that extra step and create a sort of private bitcoin payment gateway. It allows for generation of new addresses and confirmation of bitcoin transactions without having bitcoind installed on the server.

Or to provide a potentially simpler alternative solution, there's also the PHP Bitcoin Address Creator (https://github.com/RobKohr/PHP-Bitcoin-Address-Creator) which is PHP script designed to execute a variant of the bitcoin-off-the-grid (https://bitcointalk.org/index.php?topic=23081.20) bash script. However the bash script has multiple dependencies so it's not exactly plug-and-play in all cases, and that's why I opted to design a pure PHP solution.

Man, where were all these implementations when I looked last week to see if it had been done? (mostly for curiousity, not a personal need at this point.)  It's hard to search for, because "xyz php" always seems to match any page about "xyz" written in PHP.  Anyways, Bitcoin SCI looks nice, and thanks for the RobKohr link too!

Edit: Oh, missed the fact that RobKohr's code is not actually native PHP, if that matters to people.