I have a data in the server that I need to encrypt or sign and send it to react application using API and in react I need to decrypt or verify the signature using the public key. Given below is python code that I'm using:
import json
from Crypto import Random
from Crypto.PublicKey import RSA
import base64
def generate_keys():
modulus_length = 256 * 10
privatekey = RSA.generate(modulus_length, Random.new().read)
publickey = privatekey.publickey()
return privatekey, publickey
def encrypt_message(a_message, publickey, privatekey):
encrypted_msg = publickey.encrypt(a_message.encode("utf-8"), 32)[0]
sign = privatekey.sign(a_message.encode("utf-8"), 32)
encoded_encrypted_msg = base64.b64encode(encrypted_msg)
return encoded_encrypted_msg.decode("utf-8"), sign;
a_message = 'Hello'
privatekey, publickey = generate_keys()
encrypted_msg, sign = encrypt_message(a_message, publickey, privatekey)
I Need to decrypt this encrypted message or verify signed data in react application is there any way to do it?