def test_encrypt_and_decrypt_should_be_reversible(self): # setup msg = "This is my party." encrypted_msg = encrypt(TEST_KEY, msg, base64_encode=False) decrypted_msg = decrypt(TEST_KEY, encrypted_msg, base64_decode=False) self.assertEqual(msg, decrypted_msg)
def test_encrypt_and_decrypt_should_optionally_encode_and_decode_in_b64(self): # setup msg = "This is my verrry fun message." encrypted_msg = encrypt(TEST_KEY, msg, base64_encode=True) # Should not raise TypeError base64.b64decode(encrypted_msg) decrypted_msg = decrypt(TEST_KEY, encrypted_msg, base64_decode=True) self.assertEqual(msg, decrypted_msg)
def _set_access_token_record(token_expiry, access_token, refresh_token): encrypted = secrets.encrypt(json.dumps(dict( token_expiry=token_expiry, access_token=access_token, refresh_token=refresh_token ))) client = boto3.client('dynamodb') client.put_item( TableName='GDriveCreds', Item={ 'Id': { 'N': '1' }, 'Record': { 'S': encrypted }, })
def test_encrypt_decrypt(self): keys = secrets.generate_keys() public = keys["public"] private = keys["private"] self.assertEqual( secrets.decrypt(secrets.encrypt('foo', public), private), 'foo')