# External library - forge

**URL:** <https://community.postman.com/t/external-library-forge/52798>\
**Category:** Help Hub\
**Tags:** variables, collections, pre-request-script, external-library\
**Created:** [October 4, 2023, 11:51am UTC](https://community.postman.com/t/external-library-forge/52798 "2023-10-04T11:51:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mission-engineer-822](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mission-engineer-822](https://community.postman.com/u/mission-engineer-822)\
**Post date:** [October 4, 2023, 11:52am UTC](https://community.postman.com/t/external-library-forge/52798/1 "2023-10-04T11:52:00Z")

</div>

I am using this code

```auto
window = {};
    eval(pm.globals.get("forge_library"))
    const public_key = '-----BEGIN PUBLIC KEY-----\n' +
        'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDORoOSW2gbHl6s/YmS1jWxb954\n' +
        'X/jflZ2dK65oM/Bxii2Iba80IiC9+Sa1phmOVDAk+IVDsPNZ+YJ2Qg0hPmoLSLxe\n' +
        'f2A6ySJPl5su8TaGOuVZg1SRyk55bjHymQUnxryD/ml1EmBUaGcrs9FCiVBy38kg\n' +
        'eZNbCexucVQxn6OYlwIDAQAB\n' +
        '-----END PUBLIC KEY-----'

    const private_key = '-----BEGIN PRIVATE KEY-----\n' +
        'MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAM5Gg5JbaBseXqz9\n' +
        'iZLWNbFv3nhf+N+VnZ0rrmgz8HGKLYhtrzQiIL35JrWmGY5UMCT4hUOw81n5gnZC\n' +
        'DSE+agtIvF5/YDrJIk+Xmy7xNoY65VmDVJHKTnluMfKZBSfGvIP+aXUSYFRoZyuz\n' +
        '0UKJUHLfySB5k1sJ7G5xVDGfo5iXAgMBAAECgYEAk6KQZN4bQt2XsYS9RGUghOCm\n' +
        'f81g2NXCu00aROZ3vyvArxaiAVQzzwRWGkjJnb7PvoZJC0vIwKr+HxnjP9nmFufd\n' +
        '+0EnBT+imYSzrfZhfGGwyI6EIyy/XcoW5lf0xltx3w9mJicnR9kMzNtZ5mNGPMNn\n' +
        'CgAgjvZqnWYb+f6tb/ECQQD0tdpg8ts3puXclPe51my+LbKhEbyFSMzvtMTDCRmO\n' +
        'd0jrmZhQomsZacC8+l+2l6WTj5vrhVQlAVUeUJ7kldQNAkEA18q53wor6a4Cv0OL\n' +
        'xFzBWXRCMVFfyCWAFQUpTSGrIM/X4Lx30IZCShtvkdh1ky39b9T6lpOjES7MK4Dh\n' +
        'xttCMwJAUGBi6DEcm/zvxzIO5DVv5k9wOsNunoC4/4rqjf0xLcA0bV43z1RpxSEd\n' +
        'M3UxdvH8aqli10slxjnX0Ws9pWspCQJBALqSncgYzETbXaauqO5a4BUOrphjafPr\n' +
        'cGU8NCxrGsFg0p6NdO5G1pOqSvmHdIiPL9t8AjkkZs3Zb0+BvDOpqP8CQQDZhfh4\n' +
        '/c/Qzp4szj7+GXTZ1cmGwAuFo2/9uiumUAS3f19EpgoV9u9eyJ4gZPEBDvAjO961\n' +
        'kAjdja4DAy4SbCXy\n' +
        '-----END PRIVATE KEY-----'

    //encrypt text "plaintext"
    var publicKey = forge.pki.publicKeyFromPem(public_key);
    var encryptedText = forge.util.encode64(publicKey.encrypt("plaintext", 'RSA-OAEP', {
        md: forge.md.sha1.create(),
        mgf1: {
            md: forge.md.sha1.create()
        }
    }));
    console.log("encrypted text:" + encryptedText);

    // decrypt text
    var privateKey = forge.pki.privateKeyFromPem(private_key);
    var decryptedText = privateKey.decrypt(forge.util.decode64(encryptedText), 'RSA-OAEP', {
        md: forge.md.sha1.create(),
        mgf1: {
            md: forge.md.sha1.create()
        }
    });

    console.log("dectypted text:" + decryptedText);

```

The code above is from [GitHub - loveiset/RSAForPostman: add rsa encryt for postman](https://github.com/loveiset/RSAForPostman) this site

forge\_library variable is set to value from this site: [https://unpkg.com/node-forge@1.0.0/dist/forge.min.js](https://unpkg.com/node-forge@1.0.0/dist/forge.min.js)

I have an error  
ReferenceError: URLSearchParams is not defined

What is the solution for this problem?

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [October 4, 2023, 1:19pm UTC](https://community.postman.com/t/external-library-forge/52798/2 "2023-10-04T13:19:52Z")

</div>

Start by building your code up line by line and console logging the variables as you create them.

Start with the encrypt block.

Hopefully this will then show you which line is causing the error.

---

<div class="post-metadata">

**Author:** ![mission-engineer-822](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mission-engineer-822](https://community.postman.com/u/mission-engineer-822)\
**Post date:** [October 4, 2023, 1:24pm UTC](https://community.postman.com/t/external-library-forge/52798/3 "2023-10-04T13:24:48Z")

</div>

`eval(pm.globals.get("forge_library"))`  
this line cause an error

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [October 4, 2023, 2:02pm UTC](https://community.postman.com/t/external-library-forge/52798/4 "2023-10-04T14:02:31Z")

</div>

You can’t just consume the minified JS directly from the CDN (or copy it to an environment variable).

This is a node.JS application that requires a local server, from which you compile the forge.js that you can then EVAL using Postman.

Have a look here

[Postman RSA Encryption - Stack Overflow](https://stackoverflow.com/questions/49371771/postman-rsa-encryption)

and here for something that doesn’t need compiling.

[postman-util-lib | 🚀 A crypto utility library to be used from Postman Pre-request and Tests script tabs. (joolfe.github.io)](https://joolfe.github.io/postman-util-lib/)

CryptoJS is available directly in the Postman sandbox, and support HmacSHA256 but not RS256. (You might be better off using the utility I linked earlier).

[Manage API data and workflows using Postman JavaScript objects | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-external-libraries)

[crypto-js - npm (npmjs.com)](https://www.npmjs.com/package/crypto-js)

[Encrypt parameters using CryptoJS | Postman Answers | Postman API Network](https://www.postman.com/postman/workspace/postman-answers/collection/18070393-66f7caac-3005-44b2-8620-16dfb64a35f4)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [November 3, 2023, 2:03pm UTC](https://community.postman.com/t/external-library-forge/52798/5 "2023-11-03T14:03:12Z")

</div>

Closed on November 3, 2023, 2:03pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
