Reputation: 437
I am trying to load a pgpy private key and decrypt an encrypted text message.
Private_key_path = r"/content/Private_KEY.sub"
privkey, _ = pgpy.PGPKey.from_file(Private_key_path)
The key and the encrypted message manage to load without problems:
file_path=r"/content/we.csv"
message_from_file = pgpy.PGPMessage.from_file(file_path)
print(message_from_file)
The encrypoted message shows correctly:
-----BEGIN PGP MESSAGE-----
Version: BouncyCastle.NET Cryptography (net6.0) v2.0.0+4f800b4d32
hQEMA7yVCvCXVxN9AQf/Wegn6Dxk/zLWn594RJ5QAgCtmU0F+Yh3P4moL8UKuTLc
eifxnuG88dtpUpOuzc5cu9w84EBnQq+l8fMszuy0dMB6wkvbNtRZ03bOzJv1vkAD
4tudbbEH1+YfGqYj2gJRZ9LAprH/KtqL52SzUBmXdG9NrUnjFhIT3sWw6b+tfvMR
pZgpg6O1PsyIw1xdvCjoRjLyNT1eyvNw1nUP1wEi9G2blFlvsxAJnUo/SxD2qTVr
...
/dAc+aGk+DU0cHeA+P/Gon9Io2jPpgt3Ur9uahQ3mRvgpLBgvDsxD1ZhXZd44Dj4
4h+p30SJoeQUYh9lD7wsrQl9wUspo4p+jULSQRmps4wDv4KKLk/pt+ZBEQhhnJmR
/O9d2ZfL31BY1GV9bg==
=hw2Z
-----END PGP MESSAGE-----
When I try to unlock the key with the passphrase though:
with privkey.unlock('correctpassphrase') as key:
raw_message = key.decrypt(message_from_file).message
print(raw_message)
I get the following error:
NotImplementedError Traceback (most recent call last)
<ipython-input-139-f188768ef141> in <module>
----> 1 with privkey.unlock(PASSPHRASE) as key:
2 raw_message = key.decrypt(message_from_file).message
3 print(raw_message)
6 frames
/usr/lib/python3.8/contextlib.py in __enter__(self)
111 del self.args, self.kwds, self.func
112 try:
--> 113 return next(self.gen)
114 except StopIteration:
115 raise RuntimeError("generator didn't yield") from None
/usr/local/lib/python3.8/dist-packages/pgpy/pgp.py in unlock(self, passphrase)
1809 try:
1810 for sk in itertools.chain([self], self.subkeys.values()):
-> 1811 sk._key.unprotect(passphrase)
1812 del passphrase
1813 yield self
/usr/local/lib/python3.8/dist-packages/pgpy/packet/packets.py in unprotect(self, passphrase)
939
940 def unprotect(self, passphrase):
--> 941 self.keymaterial.decrypt_keyblob(passphrase)
942 del passphrase
943
/usr/local/lib/python3.8/dist-packages/pgpy/packet/fields.py in decrypt_keyblob(self, passphrase)
1351
1352 def decrypt_keyblob(self, passphrase):
-> 1353 kb = super(RSAPriv, self).decrypt_keyblob(passphrase)
1354 del passphrase
1355
/usr/local/lib/python3.8/dist-packages/pgpy/packet/fields.py in decrypt_keyblob(self, passphrase)
1252
1253 # derive the session key from our passphrase, and then unreference passphrase
-> 1254 sessionkey = self.s2k.derive_key(passphrase)
1255 del passphrase
1256
/usr/local/lib/python3.8/dist-packages/pgpy/packet/fields.py in derive_key(self, passphrase)
1017 def derive_key(self, passphrase):
1018 ##TODO: raise an exception if self.usage is not 254 or 255
-> 1019 keylen = self.encalg.key_size
1020 hashlen = self.halg.digest_size * 8
1021
/usr/local/lib/python3.8/dist-packages/pgpy/constants.py in key_size(self)
237 return ks[self]
238
--> 239 raise NotImplementedError(repr(self))
240
241 def gen_iv(self):
NotImplementedError: <SymmetricKeyAlgorithm.Plaintext: 0>
I can't find any reference on the documentation or the internet whatsoever and I'm totally lost. The passhphrase is a typical python string, it should be correct, even if it was wrong it should give a different error, I think the problem might reside with the key I loaded (which I was given and am not sure how it was created).
Please can anybody help me with any suggestion?
Upvotes: 1
Views: 709