print ( type ( private_pem ), type ( public_pem ))Īnd save the strings to.pem files with open('private.pem', 'w') as pr:Īnd print it out. decode ()īe sure that they are now strings. Now we'll convert our keys to strings, save them in.pem files and take a look at them.
print ( type ( private_key ), type ( public_key ))
We can also print these objects out at this point to be sure they are what we are expecting, which is 'class '''. There are a number of different options for key generation here, but we'll go with a key length of 1024 bits. We'll first generate a private key, and then derive the public key from the private key. message = b 'I love cryptography!'īefore we can encrypt we'll need a key pair. Now let's create a secret message to encrypt. We'll introduce you to those functions in the next unit.įirst let's install the pycryptodomex package.
Bitcoin uses elliptic curve cryptography and more specifically, the SECP256k1 curve. What we are learning here is how to work with public key cryptography which is heavily used in Bitcoin.įor this example we'll use a Python cryptography library called pycryptodomex. In this lesson we'll use Python to learn how to generate a key pair and then how to use that key pair to encrypt and decrypt data.Īgain, Bitcoin doesn't encrypt any data, all blockchain data is public.