def generate(cls, obj, fingerprint): """Generate a challenge and return the hash of the challenge and the challenge encrypted with GPG. """ secret = os.urandom(16).encode("hex") hash = hashlib.sha256(secret).hexdigest() ciphertext = gpg.encrypt(secret, fingerprint) chal = Challenge(hash) db_session.add(chal) db_session.commit() obj.chal_id = chal.id db_session.commit() return ciphertext
def test_encrypt(self): """Test the encrypt function""" ciphertext = gpg.encrypt('test', self.fp) self.assertIn('-----BEGIN PGP MESSAGE-----', str(ciphertext))