Generate Public Key From Pem File
admin 19.04.2020
- importos
- class EMode:
- DECRYPT ='decrypt'
- def writeall(filepath, data):
- wfile.write(data)
- withopen(filepath,'rb')as rfile:
- def read_or_generate_keys(public_key_filepath, private_key_filepath, key_size):
- ifos.path.exists(public_key_filepath)andos.path.exists(private_key_filepath):
- privkey_pem = readall(private_key_filepath)
- pubkey = rsa.PublicKey.load_pkcs1(pubkey_pem,'PEM')
- privkey = rsa.PrivateKey.load_pkcs1(privkey_pem,'PEM')
- pubkey, privkey = rsa.newkeys(key_size)
- pubkey_pem = pubkey.save_pkcs1()
- writeall(private_key_filepath, privkey_pem)
- return pubkey, privkey
- def encrypt(input_filepath, output_filepath, key_size, public_key_filepath, private_key_filepath):
- # Read from file or generate public and private keys
- pubkey, _ = read_or_generate_keys(public_key_filepath, private_key_filepath, key_size)
- # Read full file
- print(type(message),type(pubkey))
- writeall(output_filepath, encrypted)
- def decrypt(input_filepath, output_filepath, private_key_filepath):
- privkey_pem = readall(private_key_filepath)
- privkey = rsa.PrivateKey.load_pkcs1(privkey_pem,'PEM')
- # Read encrypted message from disk
- message = rsa.decrypt(encrypted, privkey)
- # Save decrypted message to disk
- def parse_cmd():
- parser= ArgumentParser(description='Test encrypt/decrypt file use RSA.')
- parser.add_argument('-m','--mode',type=str, required=True, choices=EMode.ALL,
- parser.add_argument('-i','--input-filepath',type=str, required=True,
- parser.add_argument('-o','--output-filepath',type=str, required=True,
- parser.add_argument('-s','--key-size',type=int, required=False, default=1024,
- parser.add_argument('--public-key',type=str, required=False,
- parser.add_argument('--private-key',type=str, required=False,
- parser.add_argument('-v','--verbose', action='store_true', default=False,
- def main():
- logging.basicConfig(level=logging.INFO)
- if options.mode EMode.ENCRYPT:
- encrypt(options.input_filepath, options.output_filepath, options.key_size, options.public_key, options.private_key)
- decrypt(options.input_filepath, options.output_filepath, options.private_key)
- logging.error('Unsupported mode {}'.format(options.mode))
- main()
Fallout 4 key to the nuka world generator game. I'm trying to get the hang of blockchain and public key cryptography, so I thought it would be fun to create a program for drawing up and promulgating government decrees - the government in question being one that I've just made up. The system is intended to work like this.
Generate Pem File
- 1 day ago # Read from file or generate public and private keys pubkey= readorgeneratekeys ( publickeyfilepath, privatekeyfilepath, keysize ) # Read full file.
- I imported the public key into my AWS EC2 account. Now I created a windows instance and to decrypt that instance password, AWS console is asking me for a.pem file. How I can get that.pem file from my two idrsa and idrsa.pub files?