Generate

  1. importos
  2. class EMode:
  3. DECRYPT ='decrypt'
  4. def writeall(filepath, data):
  5. wfile.write(data)
  6. withopen(filepath,'rb')as rfile:
  7. def read_or_generate_keys(public_key_filepath, private_key_filepath, key_size):
  8. ifos.path.exists(public_key_filepath)andos.path.exists(private_key_filepath):
  9. privkey_pem = readall(private_key_filepath)
  10. pubkey = rsa.PublicKey.load_pkcs1(pubkey_pem,'PEM')
  11. privkey = rsa.PrivateKey.load_pkcs1(privkey_pem,'PEM')
  12. pubkey, privkey = rsa.newkeys(key_size)
  13. pubkey_pem = pubkey.save_pkcs1()
  14. writeall(private_key_filepath, privkey_pem)
  15. return pubkey, privkey
  16. def encrypt(input_filepath, output_filepath, key_size, public_key_filepath, private_key_filepath):
  17. # Read from file or generate public and private keys
  18. pubkey, _ = read_or_generate_keys(public_key_filepath, private_key_filepath, key_size)
  19. # Read full file
  20. print(type(message),type(pubkey))
  21. writeall(output_filepath, encrypted)
  22. def decrypt(input_filepath, output_filepath, private_key_filepath):
  23. privkey_pem = readall(private_key_filepath)
  24. privkey = rsa.PrivateKey.load_pkcs1(privkey_pem,'PEM')
  25. # Read encrypted message from disk
  26. message = rsa.decrypt(encrypted, privkey)
  27. # Save decrypted message to disk
  28. def parse_cmd():
  29. parser= ArgumentParser(description='Test encrypt/decrypt file use RSA.')
  30. parser.add_argument('-m','--mode',type=str, required=True, choices=EMode.ALL,
  31. parser.add_argument('-i','--input-filepath',type=str, required=True,
  32. parser.add_argument('-o','--output-filepath',type=str, required=True,
  33. parser.add_argument('-s','--key-size',type=int, required=False, default=1024,
  34. parser.add_argument('--public-key',type=str, required=False,
  35. parser.add_argument('--private-key',type=str, required=False,
  36. parser.add_argument('-v','--verbose', action='store_true', default=False,
  37. def main():
  38. logging.basicConfig(level=logging.INFO)
  39. if options.mode EMode.ENCRYPT:
  40. encrypt(options.input_filepath, options.output_filepath, options.key_size, options.public_key, options.private_key)
  41. decrypt(options.input_filepath, options.output_filepath, options.private_key)
  42. logging.error('Unsupported mode {}'.format(options.mode))
  43. 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. 1 day ago  # Read from file or generate public and private keys pubkey= readorgeneratekeys ( publickeyfilepath, privatekeyfilepath, keysize ) # Read full file.
  2. 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?