File: //var/opt/nydus/ops/oscrypto/_win/__pycache__/symmetric.cpython-39.pyc
a
�,�h�x � @ sp d dl mZmZmZmZ ddlmZ ddlmZm Z m
Z
mZmZm
Z
mZmZmZmZ ddlmZ ddlmZ ddlmZmZ e� Zed kr�dd
lmZmZmZmZmZ nddl m!Z!m"Z"mZm#Z#m$Z$ g d�Z%d
d� Z&dd� Z'dd� Z(dd� Z)dd� Z*dd� Z+dd� Z,dd� Z-dd� Z.dd � Z/d!d"� Z0d#d$� Z1d%d&� Z2d'd(� Z3d)d*� Z4d+d,� Z5d-d.� Z6d/d0� Z7d1d2� Z8d3d4� Z9d5S )6� )�unicode_literals�division�absolute_import�print_function� )�pretty_message)
�buffer_from_bytes�bytes_from_buffer�deref�new�null�pointer_set�struct�struct_bytes�unwrap�write_to_buffer� )�
rand_bytes)�backend)� type_name�byte_cls� winlegacy)�advapi32�
Advapi32Const�handle_error�open_context_handle�close_context_handle)�bcrypt�BcryptConstr �open_alg_handle�close_alg_handle)�aes_cbc_no_padding_decrypt�aes_cbc_no_padding_encrypt�aes_cbc_pkcs7_decrypt�aes_cbc_pkcs7_encrypt�des_cbc_pkcs5_decrypt�des_cbc_pkcs5_encrypt�rc2_cbc_pkcs5_decrypt�rc2_cbc_pkcs5_encrypt�rc4_decrypt�rc4_encrypt�tripledes_cbc_pkcs5_decrypt�tripledes_cbc_pkcs5_encryptc C s� t | �dvrttdt | ����|s,td�}nt |�dkrJttdt |����t |�d dkrlttdt |����|td| ||d�fS ) a�
Encrypts plaintext using AES in CBC mode with a 128, 192 or 256 bit key and
no padding. This means the ciphertext must be an exact multiple of 16 bytes
long.
:param key:
The encryption key - a byte string either 16, 24 or 32 bytes long
:param data:
The plaintext - a byte string
:param iv:
The initialization vector - either a byte string 16-bytes long or None
to generate an IV
:raises:
ValueError - when any of the parameters contain an invalid value
TypeError - when any of the parameters are of the wrong type
OSError - when an error is returned by the OS crypto library
:return:
A tuple of two byte strings (iv, ciphertext)
�� � � �o
key must be either 16, 24 or 32 bytes (128, 192 or 256 bits)
long - is %s
r. �:
iv must be 16 bytes long - is %s
r zJ
data must be a multiple of 16 bytes long - is %s
�aesF��len�
ValueErrorr r �_encrypt��key�data�iv� r<