def createAddress(private_key): # print 'null' # private_key ''.join(['%x' % random.randrange(16) for x in range(0, 64)]) public_key = keyUtils.privateKeyToPublicKey(private_key) address = keyUtils.keyToAddr(private_key) wif = keyUtils.privateKeyToWif(private_key) return public_key
def address_new(request): if request.method == "POST": priv_key = keyUtils.makePrivKey() wif = keyUtils.privateKeyToWif(priv_key) addr = keyUtils.keyToAddr(priv_key) addressObj = BitcoinAddress(address=addr, priv_key=priv_key, priv_wif=wif) addressObj.save() return redirect('blog.views.post_list') else: return render(request, 'blog/post_list.html',{}) return render(request, 'blog/post_list.html',{})
def address_new(request): if request.method == "POST": priv_key = keyUtils.makePrivKey() wif = keyUtils.privateKeyToWif(priv_key) addr = keyUtils.keyToAddr(priv_key) addressObj = BitcoinAddress(address=addr, priv_key=priv_key, priv_wif=wif) addressObj.save() return redirect('blog.views.post_list') else: return render(request, 'blog/post_list.html', {}) return render(request, 'blog/post_list.html', {})
def genNewAddresses(num): addresses_list={} for i in xrange(1,num): private_key = os.urandom(32).encode('hex') addresses_list[keyUtils.keyToAddr(private_key)]=keyUtils.privateKeyToWif(private_key) #print keyUtils.keyToAddr(private_key)+ " : "+ keyUtils.privateKeyToWif(private_key) print "== Import genwallet.key in multibit == " print "=======================================" file = open('genwallet.key','a') pubkeys = open('pubkeys.txt','a') for key in addresses_list: pubkey = key line = addresses_list[key] + " 2015-01-12T01:00:17Z\n" print key + " : " + line pubkeys.write(key+"\n") file.write(line) file.close() pubkeys.close() print "======================================="
result = s + checksum print(' ', codecs.encode(result, 'hex').decode().upper()) print( ' ', codecs.encode(result, 'hex').decode() == '800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D' .lower()) leadingZeros = utils.countLeadingChars(result, '\0') print( '7 - Convert the result from a byte string into a base58 string using Base58Check encoding. This is the Wallet Import Format' ) #print(utils.base256decode( result )) print(' WIF:', utils.base58encode(utils.base256decode(result))) print(' WIF:', keyUtils.privateKeyToWif(private_key, net=net, compressed='yes')) print(' WIF:', keyUtils.privateKeyToWif(private_key, net=net, compressed='no')) #https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses print('****************************************') print('***** Private key to Bitcoin Address ***') print('****************************************') print('0 - Private ECDSA Key') #private_key = '18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725' #private_key = '1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD' print(' ', private_key) public_key = keyUtils.privateKeyToPublicKey(private_key, net=net) print('1 - Public ECDSA Key') print(' ', codecs.encode(public_key, 'hex').decode().upper())
hashlib.sha256( signableTxn.decode('hex')).digest()).digest().encode('hex') assert (parsed[1][-2:] == '01') # hashtype sig = keyUtils.derSigToHexSig(parsed[1][:-2]) public_key = parsed[2] print "public_key:", public_key public_key = keyUtils.getFullPubKeyFromCompressed(public_key) print "uncompressed public_key:", public_key vk = ecdsa.VerifyingKey.from_string(public_key[2:].decode('hex'), curve=ecdsa.SECP256k1) assert (vk.verify_digest(sig.decode('hex'), hashToSign.decode('hex'))) # Warning: this random function is not cryptographically strong and is just for example private_key = ''.join(['%x' % random.randrange(16) for x in range(0, 64)]) print keyUtils.privateKeyToWif(private_key) print keyUtils.keyToAddr(private_key) # privateKey = keyUtils.wifToPrivateKey("5HusYj2b2x4nroApgfvaSfKYZhRbKFH41bVyPooymbC6KfgSXdD") #1MMMM # signed_txn = makeSignedTransaction(privateKey, # "81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48", # output (prev) transaction hash # 0, # sourceIndex # keyUtils.addrHashToScriptPubKey("1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5"), # [[91234, #satoshis # keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa")]] # ) # 5HusYj2b2x4nroApgfvaSfKYZhRbKFH41bVyPooymbC6KfgSXdD # KyFvbums8LKuiVFHRzq2iEUsg7wvXC6fMkJC3PFLjGVQaaN9F1Ln # cU1UcuA7HRMNoJMamquHLpGMnkDQtwhSt8d3Z2UpGFdx1E4osE7D # 5JhuTf9i4fXU8nkonyWDuY8B9vq3LiqQ6vCKH7VpLib4f7hty42
from keyUtils import keyToAddr,privateKeyToWif import threading, Queue, sys import string import random def id_generator(size=8, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase): return ''.join(random.choice(chars) for _ in range(size)) salt = '[email protected]' realtarget = '1MkupVKiCik9iyfnLrJoZLx9RH4rkF3hnA' temptarget = '1L537cT8Uurxk15xPG1Nv4iPRL9TbBuRXi' counter =1 for x in range(50000): passphrase = id_generator() result = generate_keypair(passphrase, salt) private = privateKeyToWif(result) public = keyToAddr(result) if public[:2] == '1M': print private print public print passphrase if public == realtarget: print 'WIN - passphrase:' print passphrase with open("win", "w") as k: k.write(passphrase) k.close break print "result and counter: " with open("temp1m", "a") as fi: fi.write(passphrase +'\n')
import random import keyUtils private_key = ''.join(['%x' % random.randrange(16) for x in range(0, 64)]) print keyUtils.privateKeyToWif(private_key) print keyUtils.keyToAddr(private_key)
second_hash = hashlib.sha256(codecs.decode(first_hash.encode("utf-8"), "hex")).hexdigest() print (' ',second_hash.upper()) print(' ',second_hash == '507A5B8DFED0FC6FE8801743720CEDEC06AA5C6FCA72B07C49964492FB98A714'.lower()) print( '5 - Take the first 4 bytes of the second SHA-256 hash, this is the checksum') checksum = hashlib.sha256(hashlib.sha256(s).digest()).digest()[0:4] print (' ',hashlib.sha256(hashlib.sha256(s).digest()).hexdigest()[0:8]) print('6 - Add the 4 checksum bytes from point 5 at the end of the extended key from point 2') result = s + checksum print (' ',codecs.encode(result,'hex').decode().upper()) print (' ',codecs.encode(result,'hex').decode()=='800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D'.lower()) leadingZeros = utils.countLeadingChars(result, '\0') print('7 - Convert the result from a byte string into a base58 string using Base58Check encoding. This is the Wallet Import Format') #print(utils.base256decode( result )) print (' WIF:', utils.base58encode(utils.base256decode( result ))) print (' WIF:', keyUtils.privateKeyToWif( private_key , net=net, compressed='yes')) print (' WIF:', keyUtils.privateKeyToWif( private_key , net=net, compressed='no')) #https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses print('****************************************') print('***** Private key to Bitcoin Address ***') print('****************************************') print('0 - Private ECDSA Key') #private_key = '18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725' #private_key = '1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD' print(' ',private_key) public_key = keyUtils.privateKeyToPublicKey(private_key, net = net) print('1 - Public ECDSA Key') print(' ',codecs.encode(public_key,'hex').decode().upper())
### Generando claves y direcciones ################################################### #https://lh4.googleusercontent.com/-p8yVJXqY7fg/UuLaPjMDtyI/AAAAAAAAWYQ/QoenRIBO1O4/s588/bitcoinkeys.png ## ECDSA ### #### Clave privada = secuencia aleatoria de 256 bits. Sin embargo se representa usando mas bits #### para poder detectar errores. Ver http://bitcoin.stackexchange.com/questions/3041/what-is-a-130-hex-character-public-key # Warning: this random function is not cryptographically strong and is just for example private_key = ''.join(['%x' % random.randrange(16) for x in range(0, 64)]) #private_key = "df2c58b37905768fd39402f74f577a2c4c27ff82dd7c8a3cc0312122dc6f081d" print "Clave privada en formato hexadecimal: " + str(private_key) wif_private_key = keyUtils.privateKeyToWif(private_key) print "Clave privada en formato WIF: " + str(wif_private_key) ### Clave publica desde la clave privada public_key = keyUtils.privateKeyToPublicKey(private_key) print "Clave publica en formato hexadecimal: " + str(public_key) print "Nota: la clave publica es dos veces mas larga (un poquito mas) que la clave privada" print "|private_key| = " + str(len(private_key)) print "|public_key| = " + str(len(public_key)) #### Direccion desde la clave publica bitcoin_address = keyUtils.pubKeyToAddr(public_key) print "Direccion bitcoin: " + bitcoin_address ### Comparar con brainwallet
def _priv_to_wif(self): if self.priv_key != None: self.priv_wif = keyUtils.privateKeyToWif( self.priv_key.encode('hex')) else: print("[!]Setup private key first")