Guest User

Untitled

a guest
Apr 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #!/usr/local/bin/python3
  2.  
  3. import os
  4. import gnupg
  5. import ipfsapi
  6.  
  7. # Set GPG Home directory
  8. gpg = gnupg.GPG(homedir='')
  9. fileToEncrypt = input("Full path to file to encrypted and posted n:")
  10. encryptedFile = (fileToEncrypt + ".gpg")
  11.  
  12. def encryptFileFunction():
  13. passphrase = input("Password you would like encrypt with n:")
  14. with open(fileToEncrypt, 'rb') as f:
  15. status = gpg.encrypt(f,
  16. encrypt=False,
  17. symmetric='AES256',
  18. passphrase=passphrase,
  19. armor=False,
  20. output=fileToEncrypt + ".gpg")
  21.  
  22. def ipfsFileFunction(encryptedFile):
  23. # Tell module where IPFS instance is located
  24. api = ipfsapi.connect('127.0.0.1', 5001)
  25. # Add Encrypted file to IPFS
  26. ipfsLoadedFile = api.add(encryptedFile)
  27. # Return Hash of new IPFS File
  28. ipfsHash = (ipfsLoadedFile['Hash'])
  29. return ipfsHash
  30.  
  31. def delEncryptedFile(encryptedFile):
  32. if os.path.isfile(encryptedFile):
  33. os.remove(encryptedFile)
  34. else:
  35. print("Error: %s file not found" % encryptedFile)
  36.  
  37. def main():
  38. encryptFileFunction()
  39. ipfsFileFunction(encryptedFile)
  40. print ("File encrypted and added to IPFS with this hash " + ipfsFileFunction(encryptedFile))
  41. delEncryptedFile(encryptedFile)
  42.  
  43. main()
Add Comment
Please, Sign In to add comment