Team Ai
Apppublic

Underground-Digital/Workflow-Engine

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
test_rsa.py30 linesDownload Raw Back to libs
1import rsa as pyrsa2from Crypto.PublicKey import RSA3 4from libs import gmpy2_pkcs10aep_cipher5 6 7def test_gmpy2_pkcs10aep_cipher() -> None:8    rsa_key_pair = pyrsa.newkeys(2048)9    public_key = rsa_key_pair[0].save_pkcs1()10    private_key = rsa_key_pair[1].save_pkcs1()11 12    public_rsa_key = RSA.import_key(public_key)13    public_cipher_rsa2 = gmpy2_pkcs10aep_cipher.new(public_rsa_key)14 15    private_rsa_key = RSA.import_key(private_key)16    private_cipher_rsa = gmpy2_pkcs10aep_cipher.new(private_rsa_key)17 18    raw_text = "raw_text"19    raw_text_bytes = raw_text.encode()20 21    # RSA encryption by public key and decryption by private key22    encrypted_by_pub_key = public_cipher_rsa2.encrypt(message=raw_text_bytes)23    decrypted_by_pub_key = private_cipher_rsa.decrypt(encrypted_by_pub_key)24    assert decrypted_by_pub_key == raw_text_bytes25 26    # RSA encryption and decryption by private key27    encrypted_by_private_key = private_cipher_rsa.encrypt(message=raw_text_bytes)28    decrypted_by_private_key = private_cipher_rsa.decrypt(encrypted_by_private_key)29    assert decrypted_by_private_key == raw_text_bytes30