I converted the closed key in the Bitcoin address, uPolzia python and php
In this state, we dissatisfied with two sides of the part -timer in the format of JSON in the compatible redemption of bitcoin.
Python
Python is a popular tongue for the walls, analysis of data and automatization. We will use the library “cryptography” for the management of cryptographic operating to generate the hash. Here’s a fragment of the code of code, which implets the closed key from the JSON format in the redeser of Bitcoin, Uspolse Python:
`Python
Delo Json
That's the cryptography.
That's cryptography.hazmat.primettifs.symmetric imperative
That's cryptography.hazmat.primitives haveh hash
That's the cryptography.hazmat.backnds Import default_backend
DEF LOAD_PRIVATE_KEY (JSON_DATA):
Private_key = json.loads (json_data) ['PrivateKey']
Key_type = json.loads (json_data) ['keytype']
If Key_type == 'Hex':
Return the bytes.
ELIF KEY_TYPE == 'PKCS8':
With Open ('PRIVATE_KEY.PEM', 'WB') How F:
F.write (Private_key.encode ())
Private_Key_pem = Open ('Private_key.pem', 'Rb'). Laws ()
PRIVATE_KEY_BYTES = serialization.load_DER_PUBLICE (Private_Key_PEM, Backnd = default_backend ()). Decod ('utf-8')
Return Private_Key_bytes
other:
Take a shutter ("Tip Key is not subjected")
DEF Convert_PRIVATE_TO_BITCOIN_ADDRESS (Private_key):
PRIVATE_KEY_BYTES = LOAD_PRIVATE_KEY (JSON.loads (Private_Key) ['PrivateKey'])
Bitcoin_address = Bytes.fromhex (Private_Key_bytes)
Read the redirest of Bitcoin, AUTHING FIRST 34 SIMVALL SHEESTDERTS
Bitcoin_address = Bitcoin_address [: 34]
Return Bitcoin_address
Primmer Using:
PRIVATE_KEY_JSON = '{"Privateky": "5jyjwrrd7sbqezl9kr9dytgrybylqzehptnctcvhc5t8z9ic"}'} '}'} '
PRIVATE_KEY_HEX = Private_Key_json ['Privateky']
bitcoin_address = convert_private_to_bitcoin_address (Private_Key_hex)
Print (Bitcoin_address)
PHP
PHP - This is a popullar language for web -clearing, wall -wide and automatization. We will use the "hash" for the creation of a partial key in the format of JSON. Here's a fragment of the sight of the code, which brings the closed key from the format JSON B REST BITCOIN, Uspolse PHP:
PHP
Convert_Private_to_Bitcoin_address ($ Private_key) Function
$ PRIVATEKE = JSON_DECODE ($ PRIVATE_KEY, TRUE);
// Download the closed key out of the file (replace on your own)
$ Private_Key_pem = fopen ('Path/to/Private/Key.pem', 'RB');
$ Private_key_bytes = Fread ($ Private_Key_pem, Filesize ('Path/To/Private/Key.pem');
Fclose ($ Private_Key_pem);
// Convert byte closed key in six
$ PrivateKeyhex = Bin2hex ($ PrivateKey_bytes);
// Disperate the Bitcoin's remuneration, united the first 34 Symbol six -handed stroke
$ Bitcoinaddress = Substr ($ PrivateKeyhex, 0, 34);
return $ Bitcoinaddress;
}
// Primer Using:
$ Privatekeys = '{"Privateky": "5jyjwrrd7sbqezl9kr9dytgrxylqzehptncvhc5t8zvwgs9ic"};
$ Bitcoinaddress = Convert_Private_to_Bitcoin_address ($ PrivateKeyjson);
PRINT ($ Bitcoinaddress) // Visible: 18v7u8ynhkwg944tkzyyjj3fdfpvqf
Obraty unimaginia that you need to changePath/to/Private/Key .Pem 'on a factual way for your file closed key. The cruming of the one, obligatory to manage any clusters or exceptions, which can take the process of conversion in the process.
Primer Data Json
You can use the follow -up json in the category of models:
JSON
{
"Privatekey": "5jyjwrrd7sbqezl9kr9dytgrobxelqzehptncvhc5t8zvwgs9ic"
"Keytype": "Hex"
}
Change the "PrivateKey" field to a factual key in a six -tine format. For this primer, the installation is followed by` Keytype ‘.