RSA PKCS1_v1_5 Encryption in Postman JS Script

Experts,

I am new to Postman JS script and I need to convert a Python RSA encryption script in into a Postman Pre-request JS script. The Python script is as below :

from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5
import base64

dict = {
    "value": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmxCTfF/v15C044btDUflNud//JLT/pZN1cqKEYWYGY4FiLThHW8inWPeKaflCH7nrUO9CywXqB8v7kfYJIjvJv1xv0Ah5ghsQtmiscXPFkbpKlu6rpEimzh5Fy7ZYmPQ9JQoXoggCkFeYKQds581shdpiCj+Xi6UKdjcx3v4RalFTJtrY2eAJQ1ArEbFL6CtV5JAIfKEZ3VAv/txW1d3w2evMmdkdTXV35JxbobKYADdFx2/GhvkEiH6yfrSbDV4b1ewvG9NI0J5dk3642GfozjEVO7D0RW/EA3IAin5krYwaGsHCyPxVxbAexPPTDHZSsyUMpKHJK9+EPWm1t2WGwIDAQAB"
}

def getEncryptedText(rsaKey, secret):
        keyDER = base64.b64decode(rsaKey)
        keyPub = RSA.importKey(keyDER)
        cipherRSA = PKCS1_v1_5.new(keyPub)
        ciphertext = cipherRSA.encrypt(str.encode(secret))
        emsg = base64.b32encode(ciphertext)
        return emsg.decode()

uid = 'mytext'

public_key = dict['value']
encrypted_pubkey = getEncryptedText(public_key,uid)
print(encrypted_pubkey)

Can anybody show me the direction? or help please ?

Hi @smukherjee4

You could have a look at this workspace that has examples of using cryptojs in Postman:

I may have another example somewhere that includes PKCS but will have to have a dig around.

Hi @w4dd325/James,
I am having RSA private key with me , but not able to generate JWT token in Postman. Is there any way to generate it. if any one having script to generate token in postman it will be most helpful… Thanks in advance