Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method "pgpy.PGPMessage.from_file" failed to load encrypted file, generated from Kleopatra Tool #441

Open
singhrajndr opened this issue Jun 12, 2023 · 0 comments

Comments

@singhrajndr
Copy link

Hi , I am decrypting a csv file using pgpy library in databrick(Python). File I am using for test is Kleopatra tool encrypted file.

But the code fails at PGPY method pgpy.PGPMessage.from_file('/dbfs/FileStore/flct/file1_RSA_csv.gpg') And throws error:
NotImplementedError: <class 'pgpy.packet.types.Opaque'>

Does not matter I use RSA or ECDSA in Kleopatra to encrypt the file, error remain same.
So here is the complete flow.

Registered/Generated Key in Kleopatra based on RSA ( Without +RSA) --> Manually uploaded encrypted file in databrick HDFS file folder --> Called method pgpy.PGPMessage.from_file('/dbfs/FileStore/flct/file1_RSA_csv.gpg') to read the file --> Error

About Kleopatra:
Download Link: https://www.gpg4win.de/index.html
Uses: GnuPG 2.4.0
Libgcrypt 1.10.1

CODE STARTS HERE

decrypt_key = """-----BEGIN PGP PRIVATE KEY BLOCK-----

lQVYBGSBozkBDACucp8B0HV5RDswm+AN/zvjiNxWoYG5krlcD/t//WoIUZKi8k8x
tNPamZ2Tv8/zfAx809bT1x1lDeOFyd6TCwCxIr99IiLiYOeB9A+NgHBJic8cMdzS
oeHf6cUZcoAZB/EOFUna5ijaPz5I7Z3SVewK+imHELf7rGmermFVGcUc9MWW3Qug
K5BYrnpRwU2VTCS2gxrYVE5xWvSlpjBlcpGuwG+XZizk7kz9NEqC6IJq9L1VRWoL
0osAoPT9HfoX9nz00K7KwYCXsi0JKSDD3ypQ3c8hV5tnuaMoqct+gdMaxDL+hKAQ
/Ibn1JPqJeTgcyNeDwq4i09bEzcWstyxR3ZCYIr9W6lRRDEs5suwDqSmBA+rgTie
l+MLXKNrW7h8VEM5zqc9J/TWBg+eh+ZFlentr5T2ghGg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ATE KEY BLOCK-----
"""
priv_key = pgpy.PGPKey()
priv_key.parse(decrypt_key)
pass

#PGP Deryption start
message_from_file = pgpy.PGPMessage.from_file('/dbfs/FileStore/flct/file1_RSA_csv.gpg')
raw_message = priv_key.decrypt(message_from_file).message
with open('/dbfs/FileStore/flct/file1_RSA_output.csv', "w") as csv_file:
  csv_file.write(raw_message)
print("Decryption Complete :" + str(timer()-t0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant