
    L$jA$                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJrJ	r	  SSK
Jr  SSKJr  SSKJr   " S S	5      r\S
:X  a;  SrSrSrSr\" \\\5      r\R/                  \5      r\" \R4                  " \SS95        gg)uJ  
╔══════════════════════════════════════════════════════════════════════╗
║           🔐 Amazon SiegeCrypto - Client Side Encryption             ║
║                     (CSE - Python Implementation)                    ║
╚══════════════════════════════════════════════════════════════════════╝
📌 DESCRIPTION
This module implements Amazon SiegeCrypto Client-Side Encryption (CSE)
logic in Python, emulating the encryption flow normally performed
in the browser (clientside.js bundle).

🛠 INSTALL (one-line CLI)
pip install cryptography
────────────────────────────────────────────────────────────────────────
📥 BASIC USAGE

1. Define your key parameters (from Amazon's JavaScript):
   jwk_n = "rwLCVK_8hcUgil9KQiN7Rbtm..."
   key_id = "973900addb061fbe5bb4ea871e9d8161"
   provider_id = "si:md5"

2. Create the encryption context:
   context = CseAmazonSxgitario(jwk_n, key_id, provider_id)

3. Run encryption:
   result = context.encrypt("YourPassword123")

4. Retrieve the encrypted passwords:
   result["encryptedPassword"]
   result["encryptedPasswordCheck"]
────────────────────────────────────────────────────────────────────────
📤 OUTPUT

The `encrypt` method returns a dictionary:

{
    "status": True/False,
    "payload": original password,
    "context": description,
    "encryptedPassword": "AYAAF...",
    "encryptedPasswordCheck": "AYAAF..."
}
────────────────────────────────────────────────────────────────────────
⚠️ NOTES

- The JWK (n, e) and key_id must match Amazon's current public key.
- This script uses AWS Encryption SDK format.
- RSA-OAEP with SHA-1 is used for key wrapping.
- AES-128-GCM is used for content encryption.
- A random Message ID and Data Key are generated for every encryption.
────────────────────────────────────────────────────────────────────────
👨‍💻 AUTHOR / CREDITS

Powered by: - Vxsilisk @ Sagitario API Gateway Services -
DEV:  https://t.me/Vxsilisk
SHOP: https://t.me/Sxgitario
────────────────────────────────────────────────────────────────────────
✨ TIP

If you are replicating real browser traffic:
- Keep headers consistent
- Use proxies if needed
- Sync cookies and session properly
────────────────────────────────────────────────────────────────────────
    N)AESGCM)OAEPMGF1)RSAPublicNumbers)SHA1)default_backendc            	           \ rS rSrSrSrSrSS\S\S\SS	4S
 jjrS\S\	4S jr
S rS rS\	S\4S jrS\S\S\S\4S jrS\4S jrS\S\4S jrS\S\4S jrSrg	)CseAmazonSxgitarioJ            jwk_nkey_idprovider_idreturnNc                 (    Xl         X l        X0l        g )N)_CseAmazonSxgitario__jwkN_CseAmazonSxgitario__keyId_CseAmazonSxgitario__providerId)selfr   r   r   s       =C:\Users\Teconew\Desktop\TecoChk\amazon\cseAmazonSxgitario.py__init__CseAmazonSxgitario.__init__Q   s    '    passwordc                 4    U R                  U5      nU R                  U5      nSUSS[        R                  " U5      R                  S5      [        R                  " U5      R                  S5      S.nU$ ! [         a  nS[        U5      S.s S nA$ S nAff = f)NTz)Amazon SiegeCrypto Client Side Encryptionz)Vxsilisk @ Sxgitario API Gateways Serviceutf-8)statuspayloadcontext	poweredByencryptedPasswordencryptedPasswordCheckF)r   description)#_CseAmazonSxgitario__encryptMessagebase64	b64encodedecode	Exceptionstr)r   r   enc1enc2resulterrors         r   encryptCseAmazonSxgitario.encryptW   s    	@((2D((2D #FH%+%5%5d%;%B%B7%K*0*:*:4*@*G*G*PF M 	@#CJ??	@s   A2A5 5
B?BBBc                 ^    [         R                  " USS[        U5      S-  -
  S-  -  -   5      $ )N=   )r'   urlsafe_b64decodelen)r   ss     r   <lambda>CseAmazonSxgitario.<lambda>j   s-    V%=%=a#!cRSfWXj.\]I]B^>^%_r   c                     [         R                  U R                  U R                  5      S5      n[         R                  U R                  S5      S5      n[	        X!5      R                  [        5       5      $ )NbigAQAB)int
from_bytes!_CseAmazonSxgitario__b64UrlDecoder   r   
public_keyr   )r   nes      r   __importPublicKey$CseAmazonSxgitario.__importPublicKeym   sU    NN4..t{{;UCNN4..v6>%001BCCr   r!   c           	         U(       d  [         R                  " SS5      $ [        UR                  5       5      n[         R                  " S[	        U5      5      nU Hp  u  pEUR                  S5      UR                  S5      pvU[         R                  " S[	        U5      5      U-   [         R                  " S[	        U5      5      -   U-   -  nMr     U$ )N>Hr   r   )structpacksorteditemsr6   encode)r   r!   rJ   r.   keyvaluekbvbs           r   __serializeEncryptionContext/CseAmazonSxgitario.__serializeEncryptionContexts   s    ;;tQ''w}}'T3u:.JCZZ(%,,w*?fkk$B025D#b'8RRUWWWF   r   encrypted_keyc                    UR                  S5      nUR                  S5      n[        R                  " S[        U5      5      U-   [        R                  " S[        U5      5      -   U-   [        R                  " S[        U5      5      -   U-   $ )Nr   rF   )rK   rG   rH   r6   )r   r   r   rR   pbrN   s         r   __serializeEncryptedDataKey.CseAmazonSxgitario.__serializeEncryptedDataKey~   s|    (]]7#KKc"g&+KKc"g&')+,KKc-0124AB	
r   c                     [        S5      $ )N   )bytes)r   s    r   __buildHeaderIv"CseAmazonSxgitario.__buildHeaderIv   s    Ryr   seqc                 `    [         R                  " SS5      [         R                  " SU5      -   $ )Nz>Qr   >I)rG   rH   )r   r\   s     r   __buildFrameIv!CseAmazonSxgitario.__buildFrameIv   s#    {{4#fkk$&<<<r   c           	      t   [         R                  " S5      n[         R                  " S5      nU R                  5       nUR                  U[	        [        [        5       S9[        5       S S95      nU R                  U R                  U R                  U5      n[        5       nUR                  U R                  5        UR                  U R                  5        UR                  [        R                   " SU R"                  5      5        UR                  U5        UR                  U R%                  0 5      5        UR                  [        R                   " SS5      5        UR                  U5        UR                  S5        UR                  [        R                   " SS5      5        UR                  S	5        UR                  [        R                   " S['        U5      S-   5      5        [)        U5      n[+        U5      n	U R-                  5       n
U	R                  U
S
U5      nUR/                  S5      nU R1                  S5      n[        R                   " SS5      n[        R                   " SS5      n[        R                   " S['        U5      5      nU	R                  XS
5      nUU
-   U-   U-   U-   U-   U-   U-   $ )N   )	algorithm)mgfrc   labelrF   r      r^   r   rX   r   r   l    )osurandom$_CseAmazonSxgitario__importPublicKeyr0   r   r   r   ._CseAmazonSxgitario__serializeEncryptedDataKeyr   r   	bytearrayappend_CseAmazonSxgitario__VERSION_CseAmazonSxgitario__TYPEextendrG   rH   !_CseAmazonSxgitario__ALGORITHM_ID/_CseAmazonSxgitario__serializeEncryptionContextr6   rY   r   "_CseAmazonSxgitario__buildHeaderIvrK   !_CseAmazonSxgitario__buildFrameIv)r   r   
message_iddata_keyr@   encrypted_data_keyedk_serializedheader
raw_headeraesgcm	header_ivheader_auth_tagpassword_bytesframe_ivfinal_frame_markerseq_num_bytescontent_len_bytesencrypted_contents                     r   __encryptMessage#CseAmazonSxgitario.__encryptMessage   s7   ZZ^
::b>++-
'//TDF+tvTJ

 99t||-?

 dnn%dkk"fkk$(;(;<=j!d77;<fkk$*+n%afkk$*+bfkk$H(9:;6]
!((*	 ..CD!1&&q)#[[z:D!,"KKc..AB"NN8SI   	
   		
r   )__jwkN__keyId__providerId)si:md5)__name__
__module____qualname____firstlineno__rp   rm   rn   r+   r   dictr0   r?   ri   rY   rq   rj   rr   r=   rs   r&   __static_attributes__ r   r   r
   r
   J   s     NIF(c (3 (S (PT (@ @ @& `NDD U 
s 
C 
X] 
bg 
 =# =% =4
 4
 4
r   r
   __main__aV  rwLCVK_8hcUgil9KQiN7RbtmcJV5Pt12CwbhZ1h9fvdbVRILCanjv2RNSW9l-Mq0fnRq6DLTLzX3J3TuVCZQ1wjfa-Ef1BDeXnVNaY4q0Vvl2e1e9UF-uwyK5mDyiftlPt5JcsRuFXU1dMSb5TwDiFV1UlGOc-db33zi1MlmrL5L7iyfqBQmlEoa5el5pFbmeK2wSOKBZtJja-dbVzde0jrpGlVhHDZOAlH7g8aTftqwHLVP27T9Pr0UJtaj9LIX-sg_K9-Pl7H2W9BJDTJLJi_EAAqBHTrRueejO3XbEuSGrsrphCk0ZlYqoLkobey-kubWTba5kzsWL-huF--tzQ 973900addb061fbe5bb4ea871e9d8161r   MySecretPassword123r4   )indent)__doc__jsonr'   rg   rG   +cryptography.hazmat.primitives.ciphers.aeadr   1cryptography.hazmat.primitives.asymmetric.paddingr   r   -cryptography.hazmat.primitives.asymmetric.rsar   %cryptography.hazmat.primitives.hashesr   cryptography.hazmat.backendsr   r
   r   r   r   r   r   r!   r0   r.   printdumpsr   r   r   <module>r      s   ?B    > H J 6 8z
 z
D z eE/FK$H <G__X&F	$**VA
&' r   