Server IP : 192.158.238.246 / Your IP : 18.118.104.28 Web Server : LiteSpeed System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64 User : jenniferflocom ( 1321) PHP Version : 8.1.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /opt/alt/python37/lib64/python3.7/site-packages/Crypto/Cipher/__pycache__/ |
Upload File : |
B o~�^y$ � @ sn d Z dZddgZddlZddlZddlT ddlZddlmZ ddl m Z G d d� d�Zdded �fdd�Z dS )a{ RSA encryption protocol according to PKCS#1 OAEP See RFC3447__ or the `original RSA Labs specification`__ . This scheme is more properly called ``RSAES-OAEP``. As an example, a sender may encrypt a message in this way: >>> from Crypto.Cipher import PKCS1_OAEP >>> from Crypto.PublicKey import RSA >>> >>> message = 'To be encrypted' >>> key = RSA.importKey(open('pubkey.der').read()) >>> cipher = PKCS1_OAEP.new(key) >>> ciphertext = cipher.encrypt(message) At the receiver side, decryption can be done using the private part of the RSA key: >>> key = RSA.importKey(open('privkey.der').read()) >>> cipher = PKCS1_OAP.new(key) >>> message = cipher.decrypt(ciphertext) :undocumented: __revision__, __package__ .. __: http://www.ietf.org/rfc/rfc3447.txt .. __: http://www.rsa.com/rsalabs/node.asp?id=2125. z$Id$�new�PKCS1OAEP_Cipher� N)�*)�ceil_div)�strxorc @ s8 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� ZdS ) r zBThis cipher can perform PKCS#1 v1.5 OAEP encryption or decryption.c s@ |� _ |r|� _n tjj� _|r(|� _n� fdd�� _|� _dS )a� Initialize this PKCS#1 OAEP 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. hashAlgo : hash object The hash function to use. This can be a module under `Crypto.Hash` or an existing hash object created from any of such modules. If not specified, `Crypto.Hash.SHA` (that is, SHA-1) is used. mgfunc : callable A mask generation function that accepts two parameters: a string to use as seed, and the lenth of the mask to generate, in bytes. If not specified, the standard MGF1 is used (a safe choice). label : string A label to apply to this particular encryption. If not specified, an empty string is used. Specifying a label does not improve security. :attention: Modify the mask generation function only if you know what you are doing. Sender and receiver must use the same one. c s t jj�| |� j�S )N)�CryptoZ SignatureZ PKCS1_PSSZMGF1�_hashObj)�x�y)�self� �K/opt/alt/python37/lib64/python3.7/site-packages/Crypto/Cipher/PKCS1_OAEP.py�<lambda>e � z+PKCS1OAEP_Cipher.__init__.<locals>.<lambda>N)�_keyr r ZHashZSHA�_mgf�_label)r �key�hashAlgo�mgfunc�labelr )r r �__init__D s zPKCS1OAEP_Cipher.__init__c C s | j �� S )z?Return True/1 if this cipher object can be used for encryption.)r �can_encrypt)r r r r r i s zPKCS1OAEP_Cipher.can_encryptc C s | j �� S )z?Return True/1 if this cipher object can be used for decryption.)r �can_decrypt)r r r r r m s zPKCS1OAEP_Cipher.can_decryptc C s | j j}tjj�| j j�}t|d�}| jj }t |�}|| d| d }|dk rXtd��| j�| j ��� }td�| } || td� | } ||�}| �||| d �}t| |�} | �| |�}t||�}td�| | }| j �|d�d }td�|t |� | }|S )a� Produce the PKCS#1 OAEP encryption of a message. This function is named ``RSAES-OAEP-ENCRYPT``, and is specified in section 7.1.1 of RFC3447. :Parameters: message : string The message to encrypt, also known as plaintext. It can be of variable length, but not longer than the RSA modulus (in bytes) minus 2, minus twice the hash output size. :Return: A string, the ciphertext in which the message is encrypted. It is as long as the RSA modulus (in bytes). :Raise ValueError: If the RSA key length is not sufficiently long to deal with the given message. � � r zPlaintext is too long.� )r Z _randfuncr �Util�number�size�nr r �digest_size�len� ValueErrorr r �digest�bchrr r �encrypt)r �messageZrandFunc�modBits�k�hLenZmLenZps_len�lHashZps�dbZros�dbMask�maskedDB�seedMask� maskedSeed�em�m�cr r r r&