Queryable Encryption "Local Key Must Be 69 Bytes"

I’m trying to mess a bit around with Queryable Enryption (Python!) but i can’t seem to make it work.

I’ve followed the guide step-by-step and the local key i’ve generated with “openssl rand 96 > master-key.txt” is not accepted by pymongocrypt for some reason, and i can’t figure out why.

Here’s the code i’ve used to read the .txt file and setup the ClientEncryption

provider = 'local'

path = './master-key.txt'

with open(path, 'rb') as f:

    local_master_key = f.read()

print(local_master_key) #Famous print bdebug method

kms_providers = {

    'local': {

        'key': local_master_key



client = MongoClient(connection_string)

client_encryption = ClientEncryption(






Traceback ->>

Traceback (most recent call last):
  File "c:~\mongodb_test\pymongo-fastapi-crud\make_data_key.py", line 43, in <module>
    client_encryption = ClientEncryption(
  File "C:~\mongodb_test\env-pymongo-fastapi-crud\lib\site-packages\pymongo\encryption.py", line 537, in __init__
    self._encryption = ExplicitEncrypter(
  File "C:~\mongodb_test\env-pymongo-fastapi-crud\lib\site-packages\pymongocrypt\explicit_encrypter.py", line 130, in __init__
    self.mongocrypt = MongoCrypt(mongo_crypt_opts, callback)
  File "C:~\mongodb_test\env-pymongo-fastapi-crud\lib\site-packages\pymongocrypt\mongocrypt.py", line 179, in __init__
  File "C:~\mongodb_test\env-pymongo-fastapi-crud\lib\site-packages\pymongocrypt\mongocrypt.py", line 203, in __init
  File "C:~\mongodb_test\env-pymongo-fastapi-crud\lib\site-packages\pymongocrypt\mongocrypt.py", line 259, in __raise_from_status
    raise exc
pymongocrypt.errors.MongoCryptError: local key must be 96 bytes

I’ve tried generating the key and pasting the string directly into the local.key field. I’ve tried encrypting it to base64 and many other things, but i’m still new to this encryption thing so i am really lost

Found a way to do it without OpenSSL :slight_smile:

Made a new .py which made the master-key instead of using openssl to do so

import os

path = "master-key.txt"
file_bytes = os.urandom(96)
with open(path, "wb") as f: