403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.143.209.210
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/PublicKey/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib64/python3.7/site-packages/Crypto/PublicKey/__pycache__/RSA.cpython-37.pyc
B

t~�^�t�@sDdZdZddddddgZdd	lZejdd
krDejddkrDddlTddlTdd
lmZm	Z	m
Z
ddlmZm
Z
mZddlmZddlmZmZmZdd	lZdd	lZddlmZddlmZyddlmZWnek
r�d	ZYnXGdd�dej�ZGdd�de�Zeed�e���g���Ze�Z e j!Z!e j"Z"e j#Z#e j$Z$d	S)a�RSA public-key cryptography algorithm (signature and encryption).

RSA_ is the most widespread and used public key algorithm. Its security is
based on the difficulty of factoring large integers. The algorithm has
withstood attacks for 30 years, and it is therefore considered reasonably
secure for new designs.

The algorithm can be used for both confidentiality (encryption) and
authentication (digital signature). It is worth noting that signing and
decryption are significantly slower than verification and encryption.
The cryptograhic strength is primarily linked to the length of the modulus *n*.
In 2012, a sufficient length is deemed to be 2048 bits. For more information,
see the most recent ECRYPT_ report.

Both RSA ciphertext and RSA signature are as big as the modulus *n* (256
bytes if *n* is 2048 bit long).

This module provides facilities for generating fresh, new RSA keys, constructing
them from known components, exporting them, and importing them.

    >>> from Crypto.PublicKey import RSA
    >>>
    >>> key = RSA.generate(2048)
    >>> f = open('mykey.pem','w')
    >>> f.write(RSA.exportKey('PEM'))
    >>> f.close()
    ...
    >>> f = open('mykey.pem','r')
    >>> key = RSA.importKey(f.read())

Even though you may choose to  directly use the methods of an RSA key object
to perform the primitive cryptographic operations (e.g. `_RSAobj.encrypt`),
it is recommended to use one of the standardized schemes instead (like
`Crypto.Cipher.PKCS1_v1_5` or `Crypto.Signature.PKCS1_v1_5`).

.. _RSA: http://en.wikipedia.org/wiki/RSA_%28algorithm%29
.. _ECRYPT: http://www.ecrypt.eu.org/documents/D.SPA.17.pdf

:sort: generate,construct,importKey,error
z$Id$�generate�	construct�error�	importKey�RSAImplementation�_RSAobj�N��)�*)�getRandomRange�
bytes_to_long�
long_to_bytes)�_RSA�	_slowmath�pubkey)�Random)�	DerObject�DerSequence�DerNull)�inverse)�	_fastmathc@s�eZdZdZddddddgZd7d	d
�Zdd�Zd
d�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zd8dd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd9d5d6�ZdS):rzlClass defining an actual RSA key.

    :undocumented: __getstate__, __setstate__, __repr__, __getattr__
    �n�e�d�p�q�uNcCs(||_||_|dkrt��j}||_dS)N)�implementation�keyr�new�read�	_randfunc)�selfrr�randfunc�r$�G/opt/alt/python37/lib64/python3.7/site-packages/Crypto/PublicKey/RSA.py�__init__qs

z_RSAobj.__init__cCs.||jkrt|j|�Std|jj|f��dS)Nz%s object has no %r attribute)�keydata�getattrr�AttributeError�	__class__�__name__)r"�attrnamer$r$r%�__getattr__xs
z_RSAobj.__getattr__cCstj�|||�S)a�Encrypt a piece of data with RSA.

        :Parameter plaintext: The piece of data to encrypt with RSA. It may not
         be numerically larger than the RSA module (**n**).
        :Type plaintext: byte string or long

        :Parameter K: A random parameter (*for compatibility only. This
         value will be ignored*)
        :Type K: byte string or long

        :attention: this function performs the plain, primitive RSA encryption
         (*textbook*). In real applications, you always need to use proper
         cryptographic padding, and you should not directly encrypt data with
         this method. Failure to do so may lead to security vulnerabilities.
         It is recommended to use modules
         `Crypto.Cipher.PKCS1_OAEP` or `Crypto.Cipher.PKCS1_v1_5` instead.

        :Return: A tuple with two items. The first item is the ciphertext
         of the same type as the plaintext (string or long). The second item
         is always None.
        )r�encrypt)r"Z	plaintext�Kr$r$r%r.�sz_RSAobj.encryptcCstj�||�S)a�Decrypt a piece of data with RSA.

        Decryption always takes place with blinding.

        :attention: this function performs the plain, primitive RSA decryption
         (*textbook*). In real applications, you always need to use proper
         cryptographic padding, and you should not directly decrypt data with
         this method. Failure to do so may lead to security vulnerabilities.
         It is recommended to use modules
         `Crypto.Cipher.PKCS1_OAEP` or `Crypto.Cipher.PKCS1_v1_5` instead.

        :Parameter ciphertext: The piece of data to decrypt with RSA. It may
         not be numerically larger than the RSA module (**n**). If a tuple,
         the first item is the actual ciphertext; the second item is ignored.

        :Type ciphertext: byte string, long or a 2-item tuple as returned by
         `encrypt`

        :Return: A byte string if ciphertext was a byte string or a tuple
         of byte strings. A long otherwise.
        )r�decrypt)r"�
ciphertextr$r$r%r0�sz_RSAobj.decryptcCstj�|||�S)a�Sign a piece of data with RSA.

        Signing always takes place with blinding.

        :attention: this function performs the plain, primitive RSA decryption
         (*textbook*). In real applications, you always need to use proper
         cryptographic padding, and you should not directly sign data with
         this method. Failure to do so may lead to security vulnerabilities.
         It is recommended to use modules
         `Crypto.Signature.PKCS1_PSS` or `Crypto.Signature.PKCS1_v1_5` instead.

        :Parameter M: The piece of data to sign with RSA. It may
         not be numerically larger than the RSA module (**n**).
        :Type M: byte string or long

        :Parameter K: A random parameter (*for compatibility only. This
         value will be ignored*)
        :Type K: byte string or long

        :Return: A 2-item tuple. The first item is the actual signature (a
         long). The second item is always None.
        )r�sign)r"�Mr/r$r$r%r2�sz_RSAobj.signcCstj�|||�S)a�Verify the validity of an RSA signature.

        :attention: this function performs the plain, primitive RSA encryption
         (*textbook*). In real applications, you always need to use proper
         cryptographic padding, and you should not directly verify data with
         this method. Failure to do so may lead to security vulnerabilities.
         It is recommended to use modules
         `Crypto.Signature.PKCS1_PSS` or `Crypto.Signature.PKCS1_v1_5` instead.
 
        :Parameter M: The expected message.
        :Type M: byte string or long

        :Parameter signature: The RSA signature to verify. The first item of
         the tuple is the actual signature (a long not larger than the modulus
         **n**), whereas the second item is always ignored.
        :Type signature: A 2-item tuple as return by `sign`

        :Return: True if the signature is correct, False otherwise.
        )r�verify)r"r3Z	signaturer$r$r%r4�sz_RSAobj.verifycCs|j�|�fS)N)r�_encrypt)r"�cr/r$r$r%r5�sz_RSAobj._encryptcCsN|dd�\}td|jjd|jd�}|j�||�}|j�|�}|j�||�S)Nr	)r#)rrrr!�_blind�_decrypt�_unblind)r"r6r1�rZcpZmpr$r$r%r8�s
z_RSAobj._decryptcCs|j�||�S)N)rr7)r"�mr:r$r$r%r7�sz_RSAobj._blindcCs|j�||�S)N)rr9)r"r;r:r$r$r%r9�sz_RSAobj._unblindcCs|j�|�fS)N)r�_sign)r"r;r/r$r$r%r<�sz
_RSAobj._signcCs|dd�\}|j�||�S)Nr	)r�_verify)r"r;�sig�sr$r$r%r=�sz_RSAobj._verifycCs
|j��S)N)r�has_private)r"r$r$r%r@sz_RSAobj.has_privatecCs
|j��S)N)r�size)r"r$r$r%rAsz_RSAobj.sizecCsdS)NTr$)r"r$r$r%�	can_blind	sz_RSAobj.can_blindcCsdS)NTr$)r"r$r$r%�can_encryptsz_RSAobj.can_encryptcCsdS)NTr$)r"r$r$r%�can_signsz_RSAobj.can_signcCs|j�|jj|jjf�S)N)rrrrr)r"r$r$r%�	publickeysz_RSAobj.publickeyc	CsBi}x8|jD].}yt|j|�||<Wqtk
r8YqXqW|S)N)r'r(rr))r"r�kr$r$r%�__getstate__s
z_RSAobj.__getstate__cCsVt|d�st�|_g}x&|jD]}||kr,P|�||�qW|jjjt|��|_dS)Nr)	�hasattrrrr'�append�_math�
rsa_construct�tupler)r"r�trFr$r$r%�__setstate__s
z_RSAobj.__setstate__cCszg}xF|jD]<}|dkr2|�d|��df�qt|j|�r|�|�qW|��r^|�d�d|jjt|�d�	|�fS)Nrzn(%d)r	Zprivatez
<%s @0x%x %s>�,)
r'rIrArHrr@r*r+�id�join)r"�attrsrFr$r$r%�__repr__(s
z_RSAobj.__repr__�PEMr	cs�|dk	rt|�}|dkr�t|j�}t|j�}t|d�d@rHtd�|}t|d�d@rdtd�|}d||g}d�dd�|D��}d	t�|�dd
�St	�}|�
��r<ddd
�|}	d|j|j|j|j|j
|j|jd|j|j
dt|j
|j�g	|dd�<|dk�r�|��}
t	dg�}|�t�|�td|
����nFd}	|�t�td�}t	|j|jg�}td�|��|_|�|���|dk�r�|��S|dk�r�td|	d�}
d}|�r`|	�d��r`ddl}ddlm}ddlm}|�d�}|||dd|jj�}|||||dd|jj�7}|�||jjj |�}|
td�7}
|
td�t�!|��"�td�7}
|���|�r�|j#t$��|j#}|�%�t|�|���fdd�t&dt$��d�D�}|
td��|�7}
|
td|	d �7}
|
St'd!|�S)"a$Export this RSA key.

        :Parameter format: The format to use for wrapping the key.

            - *'DER'*. Binary encoding, always unencrypted.
            - *'PEM'*. Textual encoding, done according to `RFC1421`_/`RFC1423`_.
              Unencrypted (default) or encrypted.
            - *'OpenSSH'*. Textual encoding, done according to OpenSSH specification.
              Only suitable for public keys (not private keys).
        :Type format: string

        :Parameter passphrase: In case of PEM, the pass phrase to derive the encryption key from.
        :Type passphrase: string 

        :Parameter pkcs: The PKCS standard to follow for assembling the key.
         You have two choices:

          - with **1**, the public key is embedded into an X.509 `SubjectPublicKeyInfo` DER SEQUENCE.
            The private key is embedded into a `PKCS#1`_ `RSAPrivateKey` DER SEQUENCE.
            This mode is the default.
          - with **8**, the private key is embedded into a `PKCS#8`_ `PrivateKeyInfo` DER SEQUENCE.
            This mode is not available for public keys.

         PKCS standards are not relevant for the *OpenSSH* format.
        :Type pkcs: integer

        :Return: A byte string with the encoded public or private half.
        :Raise ValueError:
            When the format is unknown.

        .. _RFC1421:    http://www.ietf.org/rfc/rfc1421.txt
        .. _RFC1423:    http://www.ietf.org/rfc/rfc1423.txt
        .. _`PKCS#1`:   http://www.ietf.org/rfc/rfc3447.txt
        .. _`PKCS#8`:   http://www.ietf.org/rfc/rfc5208.txt
        NZOpenSSHr�zssh-rsa�cSs g|]}t�dt|��|�qS)z>I)�struct�pack�len)�.0Zkpr$r$r%�
<listcomp>`sz%_RSAobj.exportKey.<locals>.<listcomp>zssh-rsa ���zRSA PRIVATEZPRIVATE)r	�r	r]zOCTET STRINGZPUBLICz
BIT STRINGZDERrTz-----BEGIN z
 KEY-----
)�DES3)�PBKDF1�zProc-Type: 4,ENCRYPTED
zDEK-Info: DES-EDE3-CBC,z

cs"g|]}t��||d���qS)�0)�binascii�
b2a_base64)rZ�i)�	binaryKeyr$r%r[�sraz	-----END z	 KEY-----z3Unknown key format '%s'. Cannot export the RSA key.)(�tobytesr
rr�bordZbchrrQrbrcrr@rrrr�encoderI�algorithmIdentifierr�payload�b�endswith�Crypto.Hash.MD5�
Crypto.Cipherr^�Crypto.Protocol.KDFr_r!�Hash�MD5r�Cipher�MODE_CBC�b2a_hex�upperZ
block_sizerYr.�range�
ValueError)r"�format�
passphraseZpkcsZeb�nb�keyparts�	keystring�derZkeyTypeZderkey�bitmapZderPKZpemZobjenc�Cryptor^r_�saltr�padding�chunksr$)rer%�	exportKey4sj$










"z_RSAobj.exportKey)N)N)rTNr	)r+�
__module__�__qualname__�__doc__r'r&r-r.r0r2r4r5r8r7r9r<r=r@rArBrCrDrErGrNrSr�r$r$r$r%r]s0

	
c@sDeZdZdZdd�Zdd�Zddd	�Zd
d�Zdd
�Zddd�Z	dS)rz�
    An RSA key factory.

    This class is only internally used to implement the methods of the `Crypto.PublicKey.RSA` module.

    :sort: __init__,generate,construct,importKey
    :undocumented: _g*, _i*
    cKsr|�dd�}|dkr,tdk	r$t|_qPt|_n$|rJtdk	r@t|_qPtd��nt|_|jj|_|�dd�|_d|_dS)a�Create a new RSA key factory.

        :Keywords:
         use_fast_math : bool
                                Specify which mathematic library to use:

                                - *None* (default). Use fastest math available.
                                - *True* . Use fast math.
                                - *False* . Use slow math.
         default_randfunc : callable
                                Specify how to collect random data:

                                - *None* (default). Use Random.new().read().
                                - not *None* . Use the specified function directly.
        :Raise RuntimeError:
            When **use_fast_math** =True but fast math is not available.
        �
use_fast_mathNzfast math module not availableZdefault_randfunc)�getrrJr�RuntimeErrorrZ_default_randfunc�_current_randfunc)r"�kwargsr�r$r$r%r&�s

zRSAImplementation.__init__cCs(|dk	r|S|jdkr"t��j|_|jS)N)r�rrr )r"r#r$r$r%�
_get_randfunc�s

zRSAImplementation._get_randfuncN�cCs~|dks|d@dkrtd��|ddks0|dkr8td��|�|�}t�||||�}|j�|j|j|j|j	|j
|j�}t||�S)a�Randomly generate a fresh, new RSA key.

        :Parameters:
         bits : int
                            Key length, or size (in bits) of the RSA modulus.
                            It must be a multiple of 256, and no smaller than 1024.

         randfunc : callable
                            Random number generation function; it should accept
                            a single integer N and return a string of random data
                            N bytes long.
                            If not specified, a new one will be instantiated
                            from ``Crypto.Random``.

         progress_func : callable
                            Optional function that will be called with a short string
                            containing the key parameter currently being generated;
                            it's useful for interactive applications where a user is
                            waiting for a key to be generated.

         e : int
                            Public RSA exponent. It must be an odd positive integer.
                            It is typically a small number with very few ones in its
                            binary representation.
                            The default value 65537 (= ``0b10000000000000001`` ) is a safe
                            choice: other common values are 5, 7, 17, and 257.

        :attention: You should always use a cryptographically secure random number generator,
            such as the one defined in the ``Crypto.Random`` module; **don't** just use the
            current time and the ``random`` module.

        :attention: Exponent 3 is also widely used, but it requires very special care when padding
            the message.

        :Return: An RSA key object (`_RSAobj`).

        :Raise ValueError:
            When **bits** is too little or not a multiple of 256, or when
            **e** is not odd or smaller than 2.
        i�rz8RSA modulus length must be a multiple of 256 and >= 1024r�zBRSA public exponent must be a positive, odd integer larger than 2.)
rwr�rZgenerate_pyrJrKrrrrrrr)r"�bitsr#Z
progress_funcrZrf�objrr$r$r%r�s)
"zRSAImplementation.generatecCs|jj|�}t||�S)a�Construct an RSA key from a tuple of valid RSA components.

        The modulus **n** must be the product of two primes.
        The public exponent **e** must be odd and larger than 1.

        In case of a private key, the following equations must apply:

        - e != 1
        - p*q = n
        - e*d = 1 mod (p-1)(q-1)
        - p*u = 1 mod q

        :Parameters:
         tup : tuple
                    A tuple of long integers, with at least 2 and no
                    more than 6 items. The items come in the following order:

                    1. RSA modulus (n).
                    2. Public exponent (e).
                    3. Private exponent (d). Only required if the key is private.
                    4. First factor of n (p). Optional.
                    5. Second factor of n (q). Optional.
                    6. CRT coefficient, (1/p) mod q (u). Optional.
        
        :Return: An RSA key object (`_RSAobj`).
        )rJrKr)r"�tuprr$r$r%rszRSAImplementation.constructc
Cs��yft�}|�|d�t|�dkrp|��rp|ddkrp|dd�=|�t|d|d��|d=|�|dd��St|�dk�r|��r�|�|dd��S|dtk�rt�}|�|d	d�|�	d
��rt
|jd�dk�r|�|jd	d�d�t|�dk�r|���r|�|dd��S|ddk�rf|d	tk�rft�}|�|dd�|�	d��rf|�|j�SWn$t
k
�r�}zWdd}~XYnXt
d��dS)
z@Import an RSA key (public or private half), encoded in DER form.T�	r�N��rr	z
BIT STRINGzOCTET STRINGzRSA key format is not supported)r�decoderYZhasOnlyIntsrIrrrirZisTypergrj�
_importKeyDERrw)r"�	externKeyr}r~Z
privateKey�
IndexErrorr$r$r%r�s6 
 zRSAImplementation._importKeyDERcCs�t|�}|dk	rt|�}|�td���r�|�td�td����}d}|d�td���rv|d�td��}t|�dks�|d	td
�ks�|s�td��|d�td��\}}t�|�}d	dl	}d	d
l
m}	m}
d	dl
m}|td�k�r|||dd|jj�}|	�||jjj|�}n\|td�k�rb|||dd|jj�}|||||dd|jj�7}|
�||jjj|�}ntd��|dd�}t�td��|dd���}
|�r�|�|
�}
t|
d�}|
d|�}
|�|
�S|�td���rlt�|�td��d�}g}xRt|�dk�rDt�d|dd��d	}|�|dd|��|d|d�}�q�Wt|d�}t|d�}|�||g�St|d	�dk�r�|�|�Std��dS)aeImport an RSA key (public or private half), encoded in standard form.

        :Parameter externKey:
            The RSA key to import, encoded as a string.

            An RSA public key can be in any of the following formats:

            - X.509 `subjectPublicKeyInfo` DER SEQUENCE (binary or PEM encoding)
            - `PKCS#1`_ `RSAPublicKey` DER SEQUENCE (binary or PEM encoding)
            - OpenSSH (textual public key only)

            An RSA private key can be in any of the following formats:

            - PKCS#1 `RSAPrivateKey` DER SEQUENCE (binary or PEM encoding)
            - `PKCS#8`_ `PrivateKeyInfo` DER SEQUENCE (binary or PEM encoding)
            - OpenSSH (textual public key only)

            For details about the PEM encoding, see `RFC1421`_/`RFC1423`_.
            
            In case of PEM encoding, the private key can be encrypted with DES or 3TDES according to a certain ``pass phrase``.
            Only OpenSSL-compatible pass phrases are supported.
        :Type externKey: string

        :Parameter passphrase:
            In case of an encrypted PEM key, this is the pass phrase from which the encryption key is derived.
        :Type passphrase: string
        
        :Return: An RSA key object (`_RSAobj`).

        :Raise ValueError/IndexError/TypeError:
            When the given key cannot be parsed (possibly because the pass phrase is wrong).

        .. _RFC1421: http://www.ietf.org/rfc/rfc1421.txt
        .. _RFC1423: http://www.ietf.org/rfc/rfc1423.txt
        .. _`PKCS#1`: http://www.ietf.org/rfc/rfc3447.txt
        .. _`PKCS#8`: http://www.ietf.org/rfc/rfc5208.txt
        Nz-----� rVr	zProc-Type:4,ENCRYPTEDr�:rzDEK-Infoz$PEM encryption format not supported.rO)�DESr^)r_zDES-CBCr]zDES-EDE3-CBCr`z#Unsupport PEM encryption algorithm.r\zssh-rsa r�z>IrazRSA key format is not supported)rf�
startswithrk�replace�splitrYrwrb�a2b_hexrmrnr�r^ror_rprqrrrrs�
a2b_base64rQr0rgr�rW�unpackrIrr)r"r�ry�linesZkeyobjZDEKZalgor�rr�r^r_rr}r�r|r{�lrrr$r$r%rNsV& 



zRSAImplementation.importKey)NNr�)N)
r+r�r�r�r&r�rrr�rr$r$r$r%r�s'
30u	*†H†÷
)%r��__revision__�__all__�sys�version_infoZCrypto.Util.py21compatZCrypto.Util.py3compatZCrypto.Util.numberrrr
ZCrypto.PublicKeyrrrrrZCrypto.Util.asn1rrrrbrWrr�ImportErrorr�objectrrkrhri�_implrrrrr$r$r$r%�<module>@s@
:!

Youez - 2016 - github.com/yon3zu
LinuXploit