crypto_7.py 777 B

12345678910111213141516171819202122232425
  1. def decrypt(self, key, ciphertext, verify=False):
  2. """ decrypt data with convergence encryption.
  3. Args
  4. key: str, encryption key
  5. cipher: str, ciphertext
  6. verify: bool, verify decrypted data, default: False
  7. Returns
  8. the plain text
  9. """
  10. plain = aes(key, ciphertext)
  11. if verify:
  12. h = SHA256d(plain)
  13. if self.__convergence_secret:
  14. h.update(self.__convergence_secret)
  15. digest = h.digest()
  16. # can verify only if convergence secret is known!
  17. if self.__convergence_secret and not key == digest:
  18. msg = "Block verification error on %s." % SHA256d(key).hexdigest()
  19. log.error(msg)
  20. raise CryptError(msg)
  21. return plain