File: //usr/local/CyberPanel/lib64/python3.10/site-packages/jose/__pycache__/jwe.cpython-310.pyc
o
��h�X � @ s, d dl Z d dlZd dlZd dlmZ d dlmZ ddlmZ ddl m
Z
ddlmZm
Z
mZ ddlmZmZ dd lmZmZmZ ejejdddfd
d�Zdd
� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Z dd� Z!dd� Z"d d!� Z#d"d#� Z$d$d%� Z%d&d'� Z&d(d)� Z'd*d+� Z(d,d-� Z)d.d/� Z*dS )0� N)�Mapping��pack� )�jwk)�get_random_bytes)�
ALGORITHMS�JWE_SIZE_LIMIT�ZIPS)�JWEError�
JWEParseError)�base64url_decode�base64url_encode�
ensure_binaryc
C s� t | �} |tjvrtd| ��|tjvrtd| ��t�||�}t|||||�}t|| �} t||||| |�\}} }
}t ||| |
|�}|S )a� Encrypts plaintext and returns a JWE cmpact serialization string.
Args:
plaintext (bytes): A bytes object to encrypt
key (str or dict): The key(s) to use for encrypting the content. Can be
individual JWK or JWK set.
encryption (str, optional): The content encryption algorithm used to
perform authenticated encryption on the plaintext to produce the
ciphertext and the Authentication Tag. Defaults to A256GCM.
algorithm (str, optional): The cryptographic algorithm used
to encrypt or determine the value of the CEK. Defaults to dir.
zip (str, optional): The compression algorithm) applied to the
plaintext before encryption. Defaults to None.
cty (str, optional): The media type for the secured content.
See http://www.iana.org/assignments/media-types/media-types.xhtml
kid (str, optional): Key ID for the provided key
Returns:
bytes: The string representation of the header, encrypted key,
initialization vector, ciphertext, and authentication tag.
Raises:
JWEError: If there is an error signing the token.
Examples:
>>> from jose import jwe
>>> jwe.encrypt('Hello, World!', 'asecret128bitkey', algorithm='dir', encryption='A128GCM')
'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIn0..McILMB3dYsNJSuhcDzQshA.OfX9H_mcUpHDeRM4IA.CcnTWqaqxNsjT4eCaUABSg'
�Algorithm %s not supported.)
r r � SUPPORTEDr r � construct�_encoded_header� _compress�_encrypt_and_auth�_jwe_compact_serialize)
� plaintext�key�
encryption� algorithm�zip�cty�kid�encoded_header�enc_cek�iv�cipher_text�auth_tag�
jwe_string� r$ �>/usr/local/CyberPanel/lib/python3.10/site-packages/jose/jwe.py�encrypt s
r&