§
    ¢”j›x  ã                   ó\  — d dl mZmZmZmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZ  e¦   «         Zed	k    rdd
lmZmZmZmZmZ nddl m!Z!m"Z"mZm#Z#m$Z$ g d¢Z%d„ Z&d„ Z'd„ Z(d„ Z)d„ Z*d„ Z+d„ Z,d„ Z-d„ Z.d„ Z/d„ Z0d„ Z1d„ Z2d„ Z3d„ Z4d„ Z5d„ Z6d„ Z7d„ Z8d „ Z9d!S )"é    )Ú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                 óÀ  — t          | ¦  «        dvr*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚|st          d¦  «        }n=t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚t          |¦  «        dz  dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚|t	          d| ||d¦  «        fS )	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
            r0   ú:
            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Úivs      úf/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/oscrypto/_win/symmetric.pyr#   r#   -   sù   € õ2 ˆ3�x„x�|Ð#Ð#Ý�ðõ �‰HŒHñ
ô 
ñ ô ð 	ð ð Ý˜‰^Œ^ˆˆÝ	ˆR‰Œ�BŠˆÝ�ðõ �‰GŒGñ	
ô 
ñ ô ð 	õ ˆ4�y„y�2�~˜ÒÐÝ�ðõ �‰IŒIñ	
ô 
ñ ô ð 	ð •˜  T¨2¨uÑ5Ô5Ð6Ð6ó    c                 ó  — t          | ¦  «        dvr*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚t          d| ||d¦  «        S )a[  
    Decrypts AES ciphertext in CBC mode using a 128, 192 or 256 bit key and no
    padding.

    :param key:
        The encryption key - a byte string either 16, 24 or 32 bytes long

    :param data:
        The ciphertext - a byte string

    :param iv:
        The initialization vector - a byte string 16-bytes long

    :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 byte string of the plaintext
    r/   r3   r0   r4   r5   F©r7   r8   r   Ú_decryptr:   s      r>   r"   r"   d   sš   € õ. ˆ3�x„x�|Ð#Ð#Ý�ðõ �‰HŒHñ
ô 
ñ ô ð 	õ ˆ2�w„w�"‚}€}Ý�ðõ �‰GŒGñ	
ô 
ñ ô ð 	õ �E˜3  b¨%Ñ0Ô0Ð0r?   c                 ó@  — t          | ¦  «        dvr*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚|st          d¦  «        }n=t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚|t	          d| ||d¦  «        fS )a™  
    Encrypts plaintext using AES in CBC mode with a 128, 192 or 256 bit key and
    PKCS#7 padding.

    :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)
    r/   r3   r0   r4   r5   Tr6   r:   s      r>   r%   r%   �   s´   € õ0 ˆ3�x„x�|Ð#Ð#Ý�ðõ �‰HŒHñ
ô 
ñ ô ð 	ð ð Ý˜‰^Œ^ˆˆÝ	ˆR‰Œ�BŠˆÝ�ðõ �‰GŒGñ	
ô 
ñ ô ð 	ð •˜  T¨2¨tÑ4Ô4Ð5Ð5r?   c                 ó  — t          | ¦  «        dvr*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚t          d| ||d¦  «        S )aG  
    Decrypts AES ciphertext in CBC mode using a 128, 192 or 256 bit key

    :param key:
        The encryption key - a byte string either 16, 24 or 32 bytes long

    :param data:
        The ciphertext - a byte string

    :param iv:
        The initialization vector - a byte string 16-bytes long

    :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 byte string of the plaintext
    r/   r3   r0   r4   r5   TrA   r:   s      r>   r$   r$   ½   sš   € õ, ˆ3�x„x�|Ð#Ð#Ý�ðõ �‰HŒHñ
ô 
ñ ô ð 	õ ˆ2�w„w�"‚}€}Ý�ðõ �‰GŒGñ	
ô 
ñ ô ð 	õ �E˜3  b¨$Ñ/Ô/Ð/r?   c                 óÈ   — t          | ¦  «        dk     st          | ¦  «        dk    r*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚t          d| |dd¦  «        S )a×  
    Encrypts plaintext using RC4 with a 40-128 bit key

    :param key:
        The encryption key - a byte string 5-16 bytes long

    :param data:
        The plaintext - a byte string

    :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 byte string of the ciphertext
    é   r0   úQ
            key must be 5 to 16 bytes (40 to 128 bits) long - is %s
            Úrc4N)r7   r8   r   r9   ©r;   r<   s     r>   r+   r+   ç   óg   € õ& ˆ3�x„x�!‚|€|•s˜3‘x”x "’}�}Ý�ðõ �‰HŒHñ	
ô 
ñ ô ð 	õ �E˜3  d¨DÑ1Ô1Ð1r?   c                 óÈ   — t          | ¦  «        dk     st          | ¦  «        dk    r*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚t          d| |dd¦  «        S )aÓ  
    Decrypts RC4 ciphertext using a 40-128 bit key

    :param key:
        The encryption key - a byte string 5-16 bytes long

    :param data:
        The ciphertext - a byte string

    :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 byte string of the plaintext
    rF   r0   rG   rH   NrA   rI   s     r>   r*   r*     rJ   r?   c                 ój  — t          | ¦  «        dk     st          | ¦  «        dk    r*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚|st          d¦  «        }n=t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚|t	          d| ||d¦  «        fS )ab  
    Encrypts plaintext using RC2 with a 64 bit key

    :param key:
        The encryption key - a byte string 8 bytes long

    :param data:
        The plaintext - a byte string

    :param iv:
        The 8-byte initialization vector to use - a byte string - set as None
        to generate an appropriate one

    :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)
    rF   r0   rG   é   ú9
            iv must be 8 bytes long - is %s
            Úrc2Tr6   r:   s      r>   r)   r)   #  sÀ   € õ. ˆ3�x„x�!‚|€|•s˜3‘x”x "’}�}Ý�ðõ �‰HŒHñ	
ô 
ñ ô ð 	ð ð Ý˜‰]Œ]ˆˆÝ	ˆR‰Œ�AŠˆÝ�ðõ �‰GŒGñ	
ô 
ñ ô ð 	ð •˜  T¨2¨tÑ4Ô4Ð5Ð5r?   c                 óB  — t          | ¦  «        dk     st          | ¦  «        dk    r*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚t          d| ||d¦  «        S )a"  
    Decrypts RC2 ciphertext using a 64 bit key

    :param key:
        The encryption key - a byte string 8 bytes long

    :param data:
        The ciphertext - a byte string

    :param iv:
        The initialization vector used for encryption - a byte string

    :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 byte string of the plaintext
    rF   r0   rG   rM   rN   rO   TrA   r:   s      r>   r(   r(   O  s¦   € õ, ˆ3�x„x�!‚|€|•s˜3‘x”x "’}�}Ý�ðõ �‰HŒHñ	
ô 
ñ ô ð 	õ ˆ2�w„w�!‚|€|Ý�ðõ �‰GŒGñ	
ô 
ñ ô ð 	õ �E˜3  b¨$Ñ/Ô/Ð/r?   c                 ó˜  — t          | ¦  «        dk    r=t          | ¦  «        dk    r*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚|st          d¦  «        }n=t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚d}t          | ¦  «        dk    rd}|t	          || ||d¦  «        fS )	a„  
    Encrypts plaintext using 3DES in either 2 or 3 key mode

    :param key:
        The encryption key - a byte string 16 or 24 bytes long (2 or 3 key mode)

    :param data:
        The plaintext - a byte string

    :param iv:
        The 8-byte initialization vector to use - a byte string - set as None
        to generate an appropriate one

    :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)
    r0   r1   úW
            key must be 16 bytes (2 key) or 24 bytes (3 key) long - is %s
            rM   rN   Útripledes_3keyÚtripledes_2keyTr6   ©r;   r<   r=   Úciphers       r>   r-   r-   x  sÙ   € õ. ˆ3�x„x�2‚~€~�#˜c™(œ( bš.˜.Ý�ðõ �‰HŒHñ	
ô 
ñ ô ð 	ð ð Ý˜‰]Œ]ˆˆÝ	ˆR‰Œ�AŠˆÝ�ðõ �‰GŒGñ	
ô 
ñ ô ð 	ð €FÝ
ˆ3�x„x�2‚~€~Ø!ˆà•˜  d¨B°Ñ5Ô5Ð6Ð6r?   c                 óp  — t          | ¦  «        dk    r=t          | ¦  «        dk    r*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚d}t          | ¦  «        dk    rd}t          || ||d¦  «        S )	aC  
    Decrypts 3DES ciphertext in either 2 or 3 key mode

    :param key:
        The encryption key - a byte string 16 or 24 bytes long (2 or 3 key mode)

    :param data:
        The ciphertext - a byte string

    :param iv:
        The initialization vector used for encryption - a byte string

    :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 byte string of the plaintext
    r0   r1   rR   rM   rN   rS   rT   TrA   rU   s       r>   r,   r,   ¨  s¿   € õ, ˆ3�x„x�2‚~€~�#˜c™(œ( bš.˜.Ý�ðõ �‰HŒHñ	
ô 
ñ ô ð 	õ ˆ2�w„w�!‚|€|Ý�ðõ �‰GŒGñ	
ô 
ñ ô ð 	ð €FÝ
ˆ3�x„x�2‚~€~Ø!ˆå�F˜C  r¨4Ñ0Ô0Ð0r?   c                 óD  — t          | ¦  «        dk    r*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚|st          d¦  «        }n=t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚|t	          d| ||d¦  «        fS )a‹  
    Encrypts plaintext using DES with a 56 bit key

    :param key:
        The encryption key - a byte string 8 bytes long (includes error
        correction bits)

    :param data:
        The plaintext - a byte string

    :param iv:
        The 8-byte initialization vector to use - a byte string - set as None
        to generate an appropriate one

    :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)
    rM   úT
            key must be 8 bytes (56 bits + 8 parity bits) long - is %s
            rN   ÚdesTr6   r:   s      r>   r'   r'   Õ  s²   € õ0 ˆ3�x„x�1‚}€}Ý�ðõ �‰HŒHñ	
ô 
ñ ô ð 	ð ð Ý˜‰]Œ]ˆˆÝ	ˆR‰Œ�AŠˆÝ�ðõ �‰GŒGñ	
ô 
ñ ô ð 	ð •˜  T¨2¨tÑ4Ô4Ð5Ð5r?   c                 ó  — t          | ¦  «        dk    r*t          t          dt          | ¦  «        ¦  «        ¦  «        ‚t          |¦  «        dk    r*t          t          dt          |¦  «        ¦  «        ¦  «        ‚t          d| ||d¦  «        S )aK  
    Decrypts DES ciphertext using a 56 bit key

    :param key:
        The encryption key - a byte string 8 bytes long (includes error
        correction bits)

    :param data:
        The ciphertext - a byte string

    :param iv:
        The initialization vector used for encryption - a byte string

    :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 byte string of the plaintext
    rM   rY   rN   rZ   TrA   r:   s      r>   r&   r&     s˜   € õ. ˆ3�x„x�1‚}€}Ý�ðõ �‰HŒHñ	
ô 
ñ ô ð 	õ ˆ2�w„w�!‚|€|Ý�ðõ �‰GŒGñ	
ô 
ñ ô ð 	õ �E˜3  b¨$Ñ/Ô/Ð/r?   c                 ó$  — d}| dk    r8t           j        t           j        t           j        dœt	          |¦  «                 }n@t           j        t           j        t           j        t           j        t           j	        dœ|          }t           j
        }t          |d¬¦  «        }t          t          d¦  «        }t          |¦  «        }t           j        |_        t           j        |_        d|_        ||_        t          t          d	¦  «        }t          |¦  «        }	||	_        t	          |¦  «        |	_        t/          |¦  «        |z   }
d}| t1          d
dg¦  «        v rt	          |¦  «        dk    rt           j        }t5          t          d¦  «        }t          j        ||
t	          |
¦  «        t9          ¦   «         ||¦  «        }t;          |¦  «         t          |¦  «        }| d
k    rVt5          t          dt	          |¦  «        dz  ¦  «        }t          j        |t           j        |d¦  «        }t;          |¦  «         | dk    rÐt          j        |t           j         |d¦  «        }t;          |¦  «         t5          t          dt           j!        ¦  «        }t          j        |t           j"        |d¦  «        }t;          |¦  «         t5          t          dt           j#        ¦  «        }t          j        |t           j$        |d¦  «        }t;          |¦  «         ||fS )a  
    Creates an HCRYPTPROV and HCRYPTKEY for symmetric encryption/decryption. The
    HCRYPTPROV must be released by close_context_handle() and the
    HCRYPTKEY must be released by advapi32.CryptDestroyKey() when done.

    :param cipher:
        A unicode string of "aes", "des", "tripledes_2key", "tripledes_3key",
        "rc2", "rc4"

    :param key:
        A byte string of the symmetric key

    :param iv:
        The initialization vector - a byte string - unused for RC4

    :return:
        A tuple of (HCRYPTPROV, HCRYPTKEY)
    Nr5   r/   )rZ   rT   rS   rO   rH   F)Úverify_onlyÚ
BLOBHEADERr   ÚPLAINTEXTKEYBLOBrO   rH   rF   zHCRYPTKEY *úDWORD *rM   )%r   ÚCALG_AES_128ÚCALG_AES_192ÚCALG_AES_256r7   ÚCALG_DESÚCALG_3DES_112Ú	CALG_3DESÚCALG_RC2ÚCALG_RC4ÚMS_ENH_RSA_AES_PROVr   r   r   r   r_   ÚbTypeÚCUR_BLOB_VERSIONÚbVersionÚreservedÚaiKeyAlgÚhdrÚ	dwKeySizer   ÚsetÚCRYPT_NO_SALTr   ÚCryptImportKeyr   r   ÚCryptSetKeyParamÚKP_EFFECTIVE_KEYLENÚKP_IVÚCRYPT_MODE_CBCÚKP_MODEÚPKCS5_PADDINGÚ
KP_PADDING)rV   r;   r=   Úcontext_handleÚalgorithm_idÚproviderÚblob_header_pointerÚblob_headerÚblob_struct_pointerÚblob_structÚblobÚflagsÚkey_handle_pointerÚresÚ
key_handleÚbufs                   r>   Ú_advapi32_create_handlesrˆ   ,  sÑ  € ð( €Nà�‚€åÔ*ÝÔ*ÝÔ*ð
ð 
õ ˆc‰(Œ(ô	ˆˆõ !Ô)Ý+Ô9Ý+Ô5Ý Ô)Ý Ô)ð
ð 
ð ôˆõ Ô0€HÝ(¨¸uÐEÑEÔE€Nå ¥¨<Ñ8Ô8ÐÝÐ,Ñ-Ô-€KÝ%Ô6€KÔÝ(Ô9€KÔØ€KÔØ'€KÔå ¥Ð+=Ñ>Ô>ÐÝÐ,Ñ-Ô-€KØ!€K„OÝ ™HœH€KÔåÐ+Ñ,Ô,¨sÑ2€Dà€EØ•�e˜U�^Ñ$Ô$Ð$Ð$­¨S©¬°Qª¨ÝÔ+ˆå�X }Ñ5Ô5ÐÝ
Ô
!ØØÝˆD‰	Œ	Ý‰ŒØØñô €Cõ �ÑÔÐåÐ*Ñ+Ô+€Jà�‚€Ý•(˜I¥s¨3¡x¤x°!¡|Ñ4Ô4ˆÝÔ'ØÝÔ-ØØñ	
ô 
ˆõ 	�SÑÔÐà�‚€ÝÔ'ØÝÔØØñ	
ô 
ˆõ 	�SÑÔÐå•(˜I¥}Ô'CÑDÔDˆÝÔ'ØÝÔ!ØØñ	
ô 
ˆõ 	�SÑÔÐå•(˜I¥}Ô'BÑCÔCˆÝÔ'ØÝÔ$ØØñ	
ô 
ˆõ 	�SÑÔÐà˜JÐ'Ð'r?   c                 ó   — d}t           j        t           j        t           j        t           j        t           j        t           j        dœ|          }	 t          |¦  «        }t           j        }t          t          d¦  «        }t          |¦  «        }t           j        |_        t           j        |_        t!          |¦  «        |_        t%          |¦  «        |z   }| dk    rWt'          t          dt!          |¦  «        dz  ¦  «        }t          j        |t           j        |dd¦  «        }	t-          |	¦  «         t'          t          d	¦  «        }
t          j        |t1          ¦   «         ||
t1          ¦   «         d|t!          |¦  «        d¦	  «	        }	t-          |	¦  «         t          |
¦  «        |rt3          |¦  «         S S # |rt3          |¦  «         w w xY w)
ao  
    Creates a BCRYPT_KEY_HANDLE for symmetric encryption/decryption. The
    handle must be released by bcrypt.BCryptDestroyKey() when done.

    :param cipher:
        A unicode string of "aes", "des", "tripledes_2key", "tripledes_3key",
        "rc2", "rc4"

    :param key:
        A byte string of the symmetric key

    :return:
        A BCRYPT_KEY_HANDLE
    N)r5   rZ   rT   rS   rO   rH   ÚBCRYPT_KEY_DATA_BLOB_HEADERrO   r`   rM   é   r   zBCRYPT_KEY_HANDLE *)r   ÚBCRYPT_AES_ALGORITHMÚBCRYPT_DES_ALGORITHMÚBCRYPT_3DES_112_ALGORITHMÚBCRYPT_3DES_ALGORITHMÚBCRYPT_RC2_ALGORITHMÚBCRYPT_RC4_ALGORITHMr    ÚBCRYPT_KEY_DATA_BLOBr   r   r   ÚBCRYPT_KEY_DATA_BLOB_MAGICÚdwMagicÚBCRYPT_KEY_DATA_BLOB_VERSION1Ú	dwVersionr7   Ú	cbKeyDatar   r   ÚBCryptSetPropertyÚBCRYPT_EFFECTIVE_KEY_LENGTHr   ÚBCryptImportKeyr   r!   )rV   r;   Ú
alg_handleÚalg_constantÚ	blob_typer€   r�   r‚   r‡   r…   r„   s              r>   Ú_bcrypt_create_key_handlerž   ›  s¶  € ð  €Jõ Ô/ÝÔ/Ý%Ô?Ý%Ô;ÝÔ/ÝÔ/ðð ð ô€Lð))Ý$ \Ñ2Ô2ˆ
ÝÔ4ˆ	å$¥VÐ-JÑKÔKÐÝÐ0Ñ1Ô1ˆÝ)ÔDˆÔÝ +Ô IˆÔÝ # C¡¤ˆÔåÐ/Ñ0Ô0°3Ñ6ˆà�UŠ?ˆ?Ý•f˜i­¨S©¬°A©Ñ6Ô6ˆCÝÔ*ØÝÔ7ØØØñô ˆCõ ˜ÑÔÐå ¥Ð)>Ñ?Ô?ÐÝÔ$ØÝ‰FŒFØØÝ‰FŒFØØÝ�‰IŒIØñ

ô 

ˆõ 	�SÑÔÐåÐ(Ñ)Ô)ð ð 	)Ý˜ZÑ(Ô(Ð(Ð(ð	)øˆ:ð 	)Ý˜ZÑ(Ô(Ð(Ð(ð	)øøøs   ÁEF9 Æ9Gc                 óP  — t          |t          ¦  «        s*t          t          dt	          |¦  «        ¦  «        ¦  «        ‚t          |t          ¦  «        s*t          t          dt	          |¦  «        ¦  «        ¦  «        ‚| dk    r?t          |t          ¦  «        s*t          t          dt	          |¦  «        ¦  «        ¦  «        ‚| dk    r-|s+| dk    rt          |¦  «        dz  dk    st          d¦  «        ‚t          d	k    rt          | ||||¦  «        S t          | ||||¦  «        S )
aÒ  
    Encrypts plaintext

    :param cipher:
        A unicode string of "aes", "des", "tripledes_2key", "tripledes_3key",
        "rc2", "rc4"

    :param key:
        The encryption key - a byte string 5-16 bytes long

    :param data:
        The plaintext - a byte string

    :param iv:
        The initialization vector - a byte string - unused for RC4

    :param padding:
        Boolean, if padding should be used - unused for RC4

    :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 byte string of the ciphertext
    ú;
            key must be a byte string, not %s
            ú<
            data must be a byte string, not %s
            rH   ú:
            iv must be a byte string, not %s
            r5   r0   r   úpadding must be specifiedr   )
Ú
isinstancer   Ú	TypeErrorr   r   r7   r8   Ú_backendÚ_advapi32_encryptÚ_bcrypt_encrypt©rV   r;   r<   r=   Úpaddings        r>   r9   r9   â  sA  € õ: �c�8Ñ$Ô$ð Ý�ðõ �c‰NŒNñ	
ô 
ñ ô ð 	õ �d�HÑ%Ô%ð Ý�ðõ �d‰OŒOñ	
ô 
ñ ô ð 	ð �‚€�z¨"­hÑ7Ô7€Ý�ðõ �b‰MŒMñ	
ô 
ñ ô ð 	ð �‚€˜w€ð ˜%’�¥C¨¡I¤I°¡N°aÒ$7Ð$7ÝÐ8Ñ9Ô9Ð9å�;ÒÐÝ  ¨¨d°B¸Ñ@Ô@Ð@Ý˜6 3¨¨b°'Ñ:Ô:Ð:r?   c           	      óN  — d}d}	 t          | ||¦  «        \  }}t          t          dt          |¦  «        ¦  «        }t          j        |t          ¦   «         ddt          ¦   «         |d¦  «        }t          |¦  «         t          |¦  «        }	t          |	¦  «        }
t          |
|¦  «         t          |t          |¦  «        ¦  «         t          j        |t          ¦   «         dd|
||	¦  «        }t          |¦  «         t          |
t          |¦  «        ¦  «        }| dk    r/|s-t          |¦  «        t          |¦  «        dz   k    r
|dd…         }||rt          j        |¦  «         |rt          |¦  «         S S # |rt          j        |¦  «         |rt          |¦  «         w w xY w)aà  
    Encrypts plaintext via CryptoAPI

    :param cipher:
        A unicode string of "aes", "des", "tripledes_2key", "tripledes_3key",
        "rc2", "rc4"

    :param key:
        The encryption key - a byte string 5-16 bytes long

    :param data:
        The plaintext - a byte string

    :param iv:
        The initialization vector - a byte string - unused for RC4

    :param padding:
        Boolean, if padding should be used - unused for RC4

    :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 byte string of the ciphertext
    Nr`   Tr   r5   r0   iðÿÿÿ)rˆ   r   r   r7   ÚCryptEncryptr   r   r   r	   r   r   r
   ÚCryptDestroyKeyr   )rV   r;   r<   r=   rª   r{   r†   Úout_lenr…   Ú
buffer_lenÚbufferÚoutputs               r>   r§   r§   "  s¼  € ð: €NØ€Jð,1Ý%=¸fÀcÈ2Ñ%NÔ%NÑ"ˆ˜
å•h 	­3¨t©9¬9Ñ5Ô5ˆÝÔ#ØÝ‰FŒFØØÝ‰FŒFØØñ
ô 
ˆõ 	�SÑÔÐå˜7‘^”^ˆ
Ý" :Ñ.Ô.ˆÝ˜ Ñ%Ô%Ð%å�G�S ™YœYÑ'Ô'Ð'ÝÔ#ØÝ‰FŒFØØØØØñ
ô 
ˆõ 	�SÑÔÐå" 6­5°©>¬>Ñ:Ô:ˆð �UŠ?ˆ? 7ˆ?­s°6©{¬{½cÀ$¹i¼iÈ"¹nÒ/LÐ/LØ˜D˜S˜D”\ˆFàð ð 	1ÝÔ$ ZÑ0Ô0Ð0Øð 	1Ý  Ñ0Ô0Ð0Ð0ð	1øð ð 	1ÝÔ$ ZÑ0Ô0Ð0Øð 	1Ý  Ñ0Ô0Ð0Ð0ð	1øøøs   †EE: Å:*F$c                 óü  — d}	 t          | |¦  «        }|€d}nt          |¦  «        }d}|du rt          j        }t	          t
          d¦  «        }t          j        ||t          |¦  «        t          ¦   «         t          ¦   «         dt          ¦   «         d||¦
  «
        }	t          |	¦  «         t          |¦  «        }
t          |
¦  «        }|rt          |¦  «        nt          ¦   «         }t          j        ||t          |¦  «        t          ¦   «         ||||
||¦
  «
        }	t          |	¦  «         t          |t          |¦  «        ¦  «        |rt          j        |¦  «         S S # |rt          j        |¦  «         w w xY w)aÚ  
    Encrypts plaintext via CNG

    :param cipher:
        A unicode string of "aes", "des", "tripledes_2key", "tripledes_3key",
        "rc2", "rc4"

    :param key:
        The encryption key - a byte string 5-16 bytes long

    :param data:
        The plaintext - a byte string

    :param iv:
        The initialization vector - a byte string - unused for RC4

    :param padding:
        Boolean, if padding should be used - unused for RC4

    :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 byte string of the ciphertext
    Nr   TúULONG *)rž   r7   r   ÚBCRYPT_BLOCK_PADDINGr   r   ÚBCryptEncryptr   r   r   r	   r
   ÚBCryptDestroyKey©rV   r;   r<   r=   rª   r†   Úiv_lenrƒ   r®   r…   r¯   r°   Ú	iv_buffers                r>   r¨   r¨   q  óƒ  € ð: €Jð10Ý.¨v°sÑ;Ô;ˆ
àˆ:ØˆFˆFå˜‘W”WˆFàˆØ�dˆ?ˆ?ÝÔ4ˆEå•f˜iÑ(Ô(ˆÝÔ"ØØÝ�‰IŒIÝ‰FŒFÝ‰FŒFØÝ‰FŒFØØØñ
ô 
ˆõ 	�SÑÔÐå˜7‘^”^ˆ
Ý" :Ñ.Ô.ˆØ-/Ð;Õ% bÑ)Ô)Ð)µT±V´Vˆ	åÔ"ØØÝ�‰IŒIÝ‰FŒFØØØØØØñ
ô 
ˆõ 	�SÑÔÐå  ­¨w©¬Ñ8Ô8ð ð 	0ÝÔ# JÑ/Ô/Ð/Ð/ð	0øˆ:ð 	0ÝÔ# JÑ/Ô/Ð/Ð/ð	0øøøó   „EE" Å"E;c                 ó2  — t          |t          ¦  «        s*t          t          dt	          |¦  «        ¦  «        ¦  «        ‚t          |t          ¦  «        s*t          t          dt	          |¦  «        ¦  «        ¦  «        ‚| dk    r?t          |t          ¦  «        s*t          t          dt	          |¦  «        ¦  «        ¦  «        ‚| t          ddg¦  «        vr|st          d¦  «        ‚t          dk    rt          | ||||¦  «        S t          | ||||¦  «        S )aè  
    Decrypts AES/RC4/RC2/3DES/DES ciphertext

    :param cipher:
        A unicode string of "aes", "des", "tripledes_2key", "tripledes_3key",
        "rc2", "rc4"

    :param key:
        The encryption key - a byte string 5-16 bytes long

    :param data:
        The ciphertext - a byte string

    :param iv:
        The initialization vector - a byte string - unused for RC4

    :param padding:
        Boolean, if padding should be used - unused for RC4

    :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 byte string of the plaintext
    r    r¡   rH   r¢   r5   r£   r   )
r¤   r   r¥   r   r   rq   r8   r¦   Ú_advapi32_decryptÚ_bcrypt_decryptr©   s        r>   rB   rB   Ä  s1  € õ: �c�8Ñ$Ô$ð Ý�ðõ �c‰NŒNñ	
ô 
ñ ô ð 	õ �d�HÑ%Ô%ð Ý�ðõ �d‰OŒOñ	
ô 
ñ ô ð 	ð �‚€�z¨"­hÑ7Ô7€Ý�ðõ �b‰MŒMñ	
ô 
ñ ô ð 	ð •S˜% ˜Ñ(Ô(Ð(Ð(°Ð(ÝÐ4Ñ5Ô5Ð5å�;ÒÐÝ  ¨¨d°B¸Ñ@Ô@Ð@Ý˜6 3¨¨b°'Ñ:Ô:Ð:r?   c                 óR  — d}d}	 t          | ||¦  «        \  }}| dk    r'|s%t          |¦  «        dz  dk    rt          d¦  «        ‚t          |¦  «        }t	          t
          dt          |¦  «        ¦  «        }t          j        |t          ¦   «         | dk    r|sdndd||¦  «        }	t          |	¦  «         t          |t          |¦  «        ¦  «        |rt          j        |¦  «         |rt          |¦  «         S S # |rt          j        |¦  «         |rt          |¦  «         w w xY w)	aö  
    Decrypts AES/RC4/RC2/3DES/DES ciphertext via CryptoAPI

    :param cipher:
        A unicode string of "aes", "des", "tripledes_2key", "tripledes_3key",
        "rc2", "rc4"

    :param key:
        The encryption key - a byte string 5-16 bytes long

    :param data:
        The ciphertext - a byte string

    :param iv:
        The initialization vector - a byte string - unused for RC4

    :param padding:
        Boolean, if padding should be used - unused for RC4

    :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 byte string of the plaintext
    Nr5   r0   r   z9Invalid data - ciphertext length must be a multiple of 16r`   FT)rˆ   r7   r8   r	   r   r   ÚCryptDecryptr   r   r
   r   r­   r   )
rV   r;   r<   r=   rª   r{   r†   r°   r®   r…   s
             r>   r½   r½     sP  € ð: €NØ€Jð1Ý%=¸fÀcÈ2Ñ%NÔ%NÑ"ˆ˜
à�UŠ?ˆ? 7ˆ?­s°4©y¬y¸2©~ÀÒ/BÐ/BÝÐXÑYÔYÐYå" 4Ñ(Ô(ˆÝ•h 	­3¨t©9¬9Ñ5Ô5ˆÝÔ#ØÝ‰FŒFð ˜u’_�_¨W�_ˆEˆE¸$ØØØñ	
ô 	
ˆõ 	�SÑÔÐå  ­¨w©¬Ñ8Ô8ð ð 	1ÝÔ$ ZÑ0Ô0Ð0Øð 	1Ý  Ñ0Ô0Ð0Ð0ð	1øð ð 	1ÝÔ$ ZÑ0Ô0Ð0Øð 	1Ý  Ñ0Ô0Ð0Ð0ð	1øøøs   †CC< Ã<*D&c                 óü  — d}	 t          | |¦  «        }|€d}nt          |¦  «        }d}|du rt          j        }t	          t
          d¦  «        }t          j        ||t          |¦  «        t          ¦   «         t          ¦   «         dt          ¦   «         d||¦
  «
        }	t          |	¦  «         t          |¦  «        }
t          |
¦  «        }|rt          |¦  «        nt          ¦   «         }t          j        ||t          |¦  «        t          ¦   «         ||||
||¦
  «
        }	t          |	¦  «         t          |t          |¦  «        ¦  «        |rt          j        |¦  «         S S # |rt          j        |¦  «         w w xY w)að  
    Decrypts AES/RC4/RC2/3DES/DES ciphertext via CNG

    :param cipher:
        A unicode string of "aes", "des", "tripledes_2key", "tripledes_3key",
        "rc2", "rc4"

    :param key:
        The encryption key - a byte string 5-16 bytes long

    :param data:
        The ciphertext - a byte string

    :param iv:
        The initialization vector - a byte string - unused for RC4

    :param padding:
        Boolean, if padding should be used - unused for RC4

    :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 byte string of the plaintext
    Nr   Tr³   )rž   r7   r   r´   r   r   ÚBCryptDecryptr   r   r   r	   r
   r¶   r·   s                r>   r¾   r¾   >  rº   r»   N):Ú
__future__r   r   r   r   Ú_errorsr   Ú_ffir	   r
   r   r   r   r   r   r   r   r   Úutilr   Ú r   Ú_typesr   r   r¦   Ú	_advapi32r   r   r   r   r   Ú_cngr   r   r    r!   Ú__all__r#   r"   r%   r$   r+   r*   r)   r(   r-   r,   r'   r&   rˆ   rž   r9   r§   r¨   rB   r½   r¾   © r?   r>   ú<module>rÍ      sÇ  ðà RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ Rà $Ð $Ð $Ð $Ð $Ð $ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (àˆ7‰9Œ9€àˆ{ÒÐØkÐkÐkÐkÐkÐkÐkÐkÐkÐkÐkÐkÐkÐkÐkàZÐZÐZÐZÐZÐZÐZÐZÐZÐZÐZÐZÐZÐZðð ð €ð 47ð 47ð 47ðn(1ð (1ð (1ðV+6ð +6ð +6ð\'0ð '0ð '0ðT2ð 2ð 2ð<2ð 2ð 2ð<)6ð )6ð )6ðX&0ð &0ð &0ðR-7ð -7ð -7ð`*1ð *1ð *1ðZ*6ð *6ð *6ðZ'0ð '0ð '0ðTl(ð l(ð l(ð^D)ð D)ð D)ðN=;ð =;ð =;ð@L1ð L1ð L1ð^P0ð P0ð P0ðf:;ð :;ð :;ðz:1ð :1ð :1ðzP0ð P0ð P0ð P0ð P0r?   