I have been working on an authentication system and I need to encrypt some information. Currently I use the python-jose library and use the jwe.encrypt()
function. On my computer it is working correctly but when I upload it to the AWS cloud as an AWS Lambda function it gives an error (see below). I would like to know if anyone has had this error and knows what has caused it?
My function to encrypt:
def generate_jwe_token(data: dict):
data["exp"] = int(time.time()) + 86700
token = jwe.encrypt(
plaintext=str(data),
key="1114A78B79D5C91189E2D4BD4C1F6"
)
return token
My serverless requirements layer section:
pythonRequirements:
useStaticCache: false
cacheLocation: "/temp_pip"
slim: false
layer:
name: ${self:provider.stage}-login-api
compatibleRuntimes:
- python3.7
- python3.8
licenseInfo: GPLv3
allowedAccounts:
- "*"
noDeploy:
- pylint
- coverage
- autopep8
My requirements file:
boto3==1.17.40
botocore==1.20.112
mysql-connector-python==8.0.22
aws-secretsmanager-caching==1.1.1.5
six==1.16.0
urllib3==1.26.12
pytest==7.1.2
pytest-cov
python-jose==3.3.0
cffi==1.15.1
cryptography==39.0.1
ecdsa==0.18.0
pyasn1==0.4.8
pycparser==2.21
rsa==4.9
Error traceback:
[ERROR] JWKError: Unable to find an algorithm for key: b'1114A78B79D5C91189E2D4BD4C1F6'
Traceback (most recent call last):
File "/var/task/functions/secret_token_rotation/rotation_token.py", line 47, in lambda_handler
create_secret(service_client, arn, token)
File "/var/task/functions/commons/rotation_steps.py", line 57, in create_secret
token_credential = generate_jwe_token(data)
File "/var/task/functions/commons/rotation_steps.py", line 166, in generate_jwe_token
key="1114A78B79D5C91189E2D4BD4C1F6"
File "/opt/python/jose/jwe.py", line 54, in encrypt
enc_cek, iv, cipher_text, auth_tag = _encrypt_and_auth(key, algorithm, encryption, zip, plaintext, encoded_header)
File "/opt/python/jose/jwe.py", line 391, in _encrypt_and_auth
encryption_key = jwk.construct(cek_bytes, enc)
File "/opt/python/jose/jwk.py", line 78, in construct
raise JWKError("Unable to find an algorithm for key: %s" % key_data)
I already tried changing the runtime of my function to python 3.8.10.
I also tried changing the encryption key.