Bitcoin Forum
November 09, 2024, 02:48:10 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Trying to have a PHP page that generates a random public/private key pair.  (Read 1358 times)
champbronc2 (OP)
Hero Member
*****
Offline Offline

Activity: 490
Merit: 500


View Profile
November 18, 2013, 01:31:18 PM
 #1

Code:
<script src="https://raw.github.com/bitcoinjs/bitcoinjs-lib/master/build/bitcoinjs-min.js"></script>




<script>

var randArr = new Uint8Array[32] //create a typed array of 32 bytes (256 bits)
window.crypto.getRandomValues(randArr) //populate array with cryptographically secure random numbers

//some Bitcoin and Crypto methods don't like Uint8Array for input. They expect regular JS arrays.
var privateKeyBytes = []
for (var i = 0; i < randArr.length; ++i)
  privateKeyBytes[i] = randArr[i]

var eckey = new (privateKeyBytes)
eckey.compressed = true
var address = eckey.getBitcoinAddress().toString()
console.log(address)// 1FkKMsKNJqWSDvTvETqcCeHcUQQ64kSC6s


var privateKeyBytesCompressed = privateKeyBytes.slice(0) //clone array
privateKeyBytesCompressed.push(0x01)
var privateKeyWIFCompressed = new Bitcoin.Address(privateKeyBytesCompressed)
privateKeyWIFCompressed.version = 0x80
privateKeyWIFCompressed = privateKeyWIFCompressed.toString()

console.log(privateKeyWIFCompressed) //KwomKti1X3tYJUUMb1TGSM2mrZk1wb1aHisUNHCQXTZq5auC2qc3


</script>


I have that on a PHP page but it is not outputting a public or private key.

How can I get the public/private key out of this? Why isn't this working?

https://bitquick.co - Buy bitcoins instantly with cash at 2% fee or Sell Bitcoins at 0% fee with BitQuick.co. Encourage safer, more secure trading! Stop selling on LocalBitcoins.
Safe trading resource: https://bitcointalk.org/index.php?topic=208203.0 Read it before you ever make a trade! Know what you're getting yourself into!
g3raint
Member
**
Offline Offline

Activity: 84
Merit: 10



View Profile
November 18, 2013, 03:26:19 PM
 #2

https://github.com/RobKohr/PHP-Bitcoin-Address-Creator
Cheers

G

------------------------------------------------------
BTC: 1NTs92VRppSsSeYLAXJtP1SxAzBwYk8JeH
------------------------------------------------------
MA5H3D
Member
**
Offline Offline

Activity: 99
Merit: 10


View Profile
November 18, 2013, 03:52:51 PM
 #3

Another option -
https://github.com/zamgo/PHPCoinAddress
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!