File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Cipher/__pycache__/PKCS1_v1_5.cpython-310.pyc
Back
o ;j� � @ s` d dgZ ddlmZ ddlmZmZ ddlmZmZm Z ddl mZ G dd� d�Zdd d �Z d S )�new�PKCS115_Cipher� )�Random)� bytes_to_long� long_to_bytes)�bord�is_bytes�_copy_bytes� )�pkcs1_decodec @ s: e Zd ZdZdd� Zdd� Zdd� Zdd � Zddd�Zd S )r z�This cipher can perform PKCS#1 v1.5 RSA encryption or decryption. Do not instantiate directly. Use :func:`Cryptodome.Cipher.PKCS1_v1_5.new` instead.c C s || _ || _dS )aJ Initialize this PKCS#1 v1.5 cipher object. :Parameters: key : an RSA key object If a private half is given, both encryption and decryption are possible. If a public half is given, only encryption is possible. randfunc : callable Function that returns random bytes. N)�_key� _randfunc)�self�key�randfunc� r �P/opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Cipher/PKCS1_v1_5.py�__init__# s zPKCS115_Cipher.__init__c C � | j �� S )z=Return True if this cipher object can be used for encryption.)r �can_encrypt�r r r r r 1 � zPKCS115_Cipher.can_encryptc C r )z=Return True if this cipher object can be used for decryption.)r �can_decryptr r r r r 5 r zPKCS115_Cipher.can_decryptc C s� | j �� }t|�}||d krtd��g }t|�|| d kr<| �d�}t|d �dkr-q|�|� t|�|| d ksd�|�}d| d td d |� }t |�}| j � |�}t||�} | S ) a� Produce the PKCS#1 v1.5 encryption of a message. This function is named ``RSAES-PKCS1-V1_5-ENCRYPT``, and it is specified in `section 7.2.1 of RFC8017 <https://tools.ietf.org/html/rfc8017#page-28>`_. :param message: The message to encrypt, also known as plaintext. It can be of variable length, but not longer than the RSA modulus (in bytes) minus 11. :type message: bytes/bytearray/memoryview :Returns: A byte string, the ciphertext in which the message is encrypted. It is as long as the RSA modulus (in bytes). :Raises ValueError: If the RSA key length is not sufficiently long to deal with the given message. � zPlaintext is too long.� r r � s � N)r � size_in_bytes�len� ValueErrorr r �append�joinr r Z_encryptr ) r �message�kZmLenZpsZnew_byte�emZem_intZm_int�cr r r �encrypt9 s"