mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
b035c02f78
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Co-authored-by: -LAN- <laipz8200@outlook.com>
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import rsa as pyrsa
|
|
from Crypto.PublicKey import RSA
|
|
|
|
from libs import gmpy2_pkcs10aep_cipher
|
|
|
|
|
|
def test_gmpy2_pkcs10aep_cipher() -> None:
|
|
rsa_key_pair = pyrsa.newkeys(2048)
|
|
public_key = rsa_key_pair[0].save_pkcs1()
|
|
private_key = rsa_key_pair[1].save_pkcs1()
|
|
|
|
public_rsa_key = RSA.import_key(public_key)
|
|
public_cipher_rsa2 = gmpy2_pkcs10aep_cipher.new(public_rsa_key)
|
|
|
|
private_rsa_key = RSA.import_key(private_key)
|
|
private_cipher_rsa = gmpy2_pkcs10aep_cipher.new(private_rsa_key)
|
|
|
|
raw_text = "raw_text"
|
|
raw_text_bytes = raw_text.encode()
|
|
|
|
# RSA encryption by public key and decryption by private key
|
|
encrypted_by_pub_key = public_cipher_rsa2.encrypt(message=raw_text_bytes)
|
|
decrypted_by_pub_key = private_cipher_rsa.decrypt(encrypted_by_pub_key)
|
|
assert decrypted_by_pub_key == raw_text_bytes
|
|
|
|
# RSA encryption and decryption by private key
|
|
encrypted_by_private_key = private_cipher_rsa.encrypt(message=raw_text_bytes)
|
|
decrypted_by_private_key = private_cipher_rsa.decrypt(encrypted_by_private_key)
|
|
assert decrypted_by_private_key == raw_text_bytes
|