Gathering detailed insights and metrics for encrypt-rsa
Gathering detailed insights and metrics for encrypt-rsa
Gathering detailed insights and metrics for encrypt-rsa
Gathering detailed insights and metrics for encrypt-rsa
npm install encrypt-rsa
Typescript
Module System
Node Version
NPM Version
TypeScript (99.74%)
Shell (0.26%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
18 Stars
122 Commits
5 Forks
1 Watchers
2 Branches
3 Contributors
Updated on May 15, 2025
Latest Version
3.3.0
Package Id
encrypt-rsa@3.3.0
Unpacked Size
44.73 kB
Size
8.80 kB
File Count
23
NPM Version
10.7.0
Node Version
18.20.4
Published on
Oct 12, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
NodeRSA is a library that provides easy-to-use methods for RSA encryption and decryption. It allows generating RSA key pairs, encrypting, and decrypting strings with RSA public and private keys. This library is ideal for secure data transmission, authentication systems, and any application requiring cryptographic security.
1npm install encrypt-rsa 2// OR 3yarn add encrypt-rsa
Importing the Library
1import NodeRSA from 'encrypt-rsa';
You can create an instance of the NodeRSA class with optional public and private keys and modulus length.
1const nodeRSA = new NodeRSA(publicKey, privateKey, modulusLength);
To generate a new pair of RSA keys:
1const { publicKey, privateKey } = nodeRSA.createPrivateAndPublicKeys(modulusLength); 2console.log('Public Key:', publicKey); 3console.log('Private Key:', privateKey);
1const text = "Hello, World!"; 2const encryptedString = nodeRSA.encryptStringWithRsaPublicKey({ text, publicKey }); 3console.log('Encrypted:', encryptedString);
1const decryptedString = nodeRSA.decryptStringWithRsaPrivateKey({ text: encryptedString, privateKey }); 2console.log('Decrypted:', decryptedString);
1const text = "Hello, World!"; 2const encryptedString = nodeRSA.encrypt({ text, privateKey }); 3console.log('Encrypted with Private Key:', encryptedString);
1const decryptedString = nodeRSA.decrypt({ text: encryptedString, publicKey }); 2console.log('Decrypted with Public Key:', decryptedString);
1constructor(publicKey?: string, privateKey?: string, modulusLength?: number)
publicKey
: Optional. The RSA public key.privateKey
: Optional. The RSA private key.modulusLength
: Optional. The modulus length for the RSA key pair (default is 2048).createPrivateAndPublicKeys(modulusLength: number = this.modulusLength): returnCreateKeys
modulusLength
: Optional. The modulus length for the RSA key pair (default is the instance's modulus length).publicKey
and privateKey
.encryptStringWithRsaPublicKey(args: parametersOfEncrypt): string
args
: Object containing text
and optionally publicKey
.decryptStringWithRsaPrivateKey(args: parametersOfDecrypt): string
args
: Object containing text
and optionally privateKey
.encrypt(args: parametersOfEncryptPrivate): string
args
: Object containing text
and optionally privateKey
.decrypt(args: parametersOfDecryptPublic): string
args
: Object containing text
and optionally publicKey
.1{ 2 text: string; 3 publicKey?: string; 4}
1{ 2 text: string; 3 privateKey?: string; 4}
1{ 2 text: string; 3 privateKey?: string; 4}
1{ 2 text: string; 3 publicKey?: string; 4}
1{ 2 publicKey: string; 3 privateKey: string; 4}
convertKetToBase64(key: string): string
Converts a given key to base64 format.encode
Encodes a string to base64.
decode
Decodes a base64 string.
NodeRSA can be used to securely transmit sensitive data over insecure channels. Encrypt data with the recipient's public key before sending it. Only the recipient can decrypt the data with their private key.
1// Sender
2const encryptedMessage = nodeRSA.encryptStringWithRsaPublicKey({ text: "Sensitive data", publicKey: recipientPublicKey });
3// Send `encryptedMessage` to the recipient
4
5// Recipient
6const decryptedMessage = nodeRSA.decryptStringWithRsaPrivateKey({ text: encryptedMessage, privateKey: recipientPrivateKey });
7console.log('Decrypted Message:', decryptedMessage);
NodeRSA can be used in authentication systems to encrypt credentials and sensitive information.
1// Encrypting user credentials
2const encryptedCredentials = nodeRSA.encryptStringWithRsaPublicKey({ text: "username:password", publicKey: serverPublicKey });
3
4// Decrypting credentials on the server
5const decryptedCredentials = nodeRSA.decryptStringWithRsaPrivateKey({ text: encryptedCredentials, privateKey: serverPrivateKey });
6console.log('Decrypted Credentials:', decryptedCredentials);
encryptBufferWithRsaPublicKey
: Converts a buffer to Base64 and then encrypts the Base64 string.decryptBufferWithRsaPrivateKey
: Decrypts the Base64 string and converts it back to a buffer.1const nodeRSA = new NodeRSA(); 2 3// Generate keys 4const { publicKey, privateKey } = nodeRSA.createPrivateAndPublicKeys(); 5 6// Example buffer 7const buffer = Buffer.from('This is some binary data'); 8 9// Encrypt the buffer 10const encryptedBuffer = nodeRSA.encryptBufferWithRsaPublicKey(buffer, publicKey); 11console.log('Encrypted Buffer:', encryptedBuffer); 12 13// Decrypt back to buffer 14const decryptedBuffer = nodeRSA.decryptBufferWithRsaPrivateKey(encryptedBuffer, privateKey); 15console.log('Decrypted Buffer:', decryptedBuffer.toString()); // should log: 'This is some binary data'
Although not directly covered by the current implementation, RSA can also be used for creating and verifying digital signatures to ensure data integrity and authenticity.
We welcome contributions to the NodeRSA library! If you'd like to contribute, please follow these steps:
1git clone git@github.com:miladezzat/encrypt-rsa.git
1git checkout -b feature/your-feature-name
1git commit -m "Description of your feature or fix"
1git push origin feature/your-feature-name
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
If you encounter any issues, please report them using the GitHub issue tracker. Include details about the problem and your environment (OS, Node.js version, etc.).
Thank you for contributing to NodeRSA!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/24 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
11 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More