Bitcoin Forum
December 08, 2016, 06:05:18 AM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1] 2 »  All
  Print  
Author Topic: how to generate a valid private-key + recv address in PHP?  (Read 12203 times)
hamdi
Hero Member
*****
Offline Offline

Activity: 644



View Profile
May 13, 2012, 06:27:43 PM
 #1

what´s the easiest way to generate a priv-key + recv-addr in php?

so i can make sites which accept bitcoin without running a daemon...

i want to do what bitaddress.org does in js, but in php.


don´t tell me to not keep private key on server... i will care about that...
i really want to do this in php, so please don´t give any arguments against my plan.

1481177118
Hero Member
*
Offline Offline

Posts: 1481177118

View Profile Personal Message (Offline)

Ignore
1481177118
Reply with quote  #2

1481177118
Report to moderator
1481177118
Hero Member
*
Offline Offline

Posts: 1481177118

View Profile Personal Message (Offline)

Ignore
1481177118
Reply with quote  #2

1481177118
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481177118
Hero Member
*
Offline Offline

Posts: 1481177118

View Profile Personal Message (Offline)

Ignore
1481177118
Reply with quote  #2

1481177118
Report to moderator
1481177118
Hero Member
*
Offline Offline

Posts: 1481177118

View Profile Personal Message (Offline)

Ignore
1481177118
Reply with quote  #2

1481177118
Report to moderator
1481177118
Hero Member
*
Offline Offline

Posts: 1481177118

View Profile Personal Message (Offline)

Ignore
1481177118
Reply with quote  #2

1481177118
Report to moderator
lulzplzkthx
Sr. Member
****
Offline Offline

Activity: 322



View Profile WWW
May 13, 2012, 06:31:29 PM
 #2

Are you putting out a bounty for this? Tongue

gweedo
Legendary
*
Offline Offline

Activity: 1246


Java, PHP, HTML/CSS Programmer for Hire!


View Profile WWW
May 13, 2012, 06:42:52 PM
 #3

https://github.com/mikegogulski/bitcoin-php/blob/master/src/bitcoin.inc#L567

this uses a bitcoind as a backend and just queries that to get a new address so that could be an answer

Want to earn 2500 SATOSHIS per hour? Come Chat and Chill in https://goseemybits.com/lobby
hamdi
Hero Member
*****
Offline Offline

Activity: 644



View Profile
May 13, 2012, 06:48:01 PM
 #4

"generate priv-key and recv-addr in pure php without a btc-daemon or any other external requirements" 


bounty is 1 BTC to the first poster who posts a working php code here.

i know there is already some code around, but i just can´t find it.

lulzplzkthx
Sr. Member
****
Offline Offline

Activity: 322



View Profile WWW
May 13, 2012, 06:48:25 PM
 #5

https://github.com/mikegogulski/bitcoin-php/blob/master/src/bitcoin.inc#L567

this uses a bitcoind as a backend and just queries that to get a new address so that could be an answer

I think hamdi's whole price is that he doesn't want to have to use bitcoind. And he doesn't have to. Now whether someone is going to write a script for him for free or not is the question.

hamdi
Hero Member
*****
Offline Offline

Activity: 644



View Profile
May 13, 2012, 06:51:20 PM
 #6

read, i set a bounty of 1 btc


Stephen Gornick
Legendary
*
Offline Offline

Activity: 2002



View Profile
May 30, 2012, 12:42:35 AM
 #7

Incidentally, a Python version here:

 - http://bitcointalk.org/index.php?topic=84238

gweedo
Legendary
*
Offline Offline

Activity: 1246


Java, PHP, HTML/CSS Programmer for Hire!


View Profile WWW
May 30, 2012, 01:38:40 AM
 #8

http://bitcoin.stackexchange.com/questions/2289/php-script-to-create-private-key-public-address

bitcoin address is in the sig Smiley

Want to earn 2500 SATOSHIS per hour? Come Chat and Chill in https://goseemybits.com/lobby
crazy_rabbit
Legendary
*
Offline Offline

Activity: 1162


RUM AND CARROTS: A PIRATE LIFE FOR ME


View Profile
August 29, 2012, 03:30:28 PM
 #9

How did this work out? I would be interested in seeing exactly how you did it in the end.

more or less retired.
hamdi
Hero Member
*****
Offline Offline

Activity: 644



View Profile
August 29, 2012, 11:59:56 PM
 #10

i use vanitygen in the back now

kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
August 30, 2012, 05:55:47 AM
 #11

By the way, this is possible to do entirely in PHP, no calls to an external program.  You need a PHP library for doing EC math (there is one, LGPL), the curve definition for secp256k1 (copies of SEC2 are available for free on the web) and a little code to glue it all together.

The nice part is that if you do it all internally, you can specify the private key rather than asking the program for one at random.

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

Activity: 19



View Profile
August 30, 2012, 07:23:35 AM
 #12

But there is no real "out of the box" PHP solution ready, right?
As most PHP based onlineshops (oscommerce, xtcommerce, zen-cart,...) run on a shared webspace, they would really benefit from a solution that does not rely on "bitcond" running as a service (or external server).
kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
August 30, 2012, 11:28:32 AM
 #13

But there is no real "out of the box" PHP solution ready, right?
As most PHP based onlineshops (oscommerce, xtcommerce, zen-cart,...) run on a shared webspace, they would really benefit from a solution that does not rely on "bitcond" running as a service (or external server).

If you don't trust the host that runs your web store with your wallet, you really shouldn't trust it with the stuff that your wallet it made of either.

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

Activity: 644



View Profile
August 30, 2012, 02:04:46 PM
 #14

i now use vanitygen via exec(); from php.
i then present the enduser with the bitcoin-address where he can pay his money,
at the same time the private-key is sent to an off-site bitcoind to be imported there.

kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
August 30, 2012, 02:30:02 PM
 #15

i now use vanitygen via exec(); from php.
i then present the enduser with the bitcoin-address where he can pay his money,
at the same time the private-key is sent to an off-site bitcoind to be imported there.

You'd be better off generating the pair remotely, and pulling the address into the customer-facing server.

The stuff that you don't want stolen is being created in the place that you are worried about it being stolen from.  That isn't a great idea, even if you delete it right away.

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

Activity: 1246


Java, PHP, HTML/CSS Programmer for Hire!


View Profile WWW
August 30, 2012, 02:37:43 PM
 #16

i now use vanitygen via exec(); from php.
i then present the enduser with the bitcoin-address where he can pay his money,
at the same time the private-key is sent to an off-site bitcoind to be imported there.

calling shell commands from a web based php script is so insecure

Want to earn 2500 SATOSHIS per hour? Come Chat and Chill in https://goseemybits.com/lobby
scintill
Sr. Member
****
Offline Offline

Activity: 448


View Profile WWW
August 31, 2012, 04:53:02 AM
 #17

For the challenge and to learn more about Bitcoin, I implemented this in pure PHP (bcmath extension required, but I think that's pretty standard. Edit: Goes much faster with GMP extension!)  Please check it over yourself before using it!  I checked several keypairs with Casascius' address utility and they look good, but I'm not an expert, and there aren't real solid tests of the code.  Most of the work is by a pre-written ECC lib I found.

Anyway, the code, with a demo embedded, is at https://gist.github.com/3549107.  It is a little slow right now but could be sped up by using GMP instead of bcmath.  I don't know if anyone still cares or if the bounty has been claimed, but it'd be nice to have. Smiley

If there's interest, let me know, and I will extend and/or test it better.

Edit: Cleaned up the code and made it use GMP if possible, as it is much much faster.  Also found ways to use the ECC lib's helper functions more, so there is less code.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
payb.tc
Hero Member
*****
Offline Offline

Activity: 812



View Profile
August 31, 2012, 04:56:39 AM
 #18

thanks, i care, and look forward to reviewing your work.
BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 966


BCJ


View Profile
October 12, 2012, 06:49:14 PM
 #19

scintill

Works like a charm.    Is there any more info on how to generate a sufficient amount of entropy when generating key pairs for real world use (line 42).

Thanks!
kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
October 12, 2012, 07:07:42 PM
 #20

scintill

Works like a charm.    Is there any more info on how to generate a sufficient amount of entropy when generating key pairs for real world use (line 42).

Thanks!

Your best bet is probably to fopen /dev/random and read 32 bytes from it.  Be warned that /dev/random will stall until it comes up with enough entropy to complete your request.  Check  /proc/sys/kernel/random/entropy_avail first, or use /dev/urandom (unsafe).

p2pcoin: a USB/CD/PXE p2pool miner - 1N8ZXx2cuMzqBYSK72X4DAy1UdDbZQNPLf - todo
I routinely ignore posters with paid advertising in their sigs.  You should too.
Pages: [1] 2 »  All
  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!