Skip to content

Commit

Permalink
feat: signing keys generation using node-js
Browse files Browse the repository at this point in the history
  • Loading branch information
sahilsharma9 committed Jan 14, 2024
1 parent 744b663 commit f45f51d
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
31 changes: 31 additions & 0 deletions utilities/signing_and_verification/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const nacl = require("tweetnacl");
const { randomBytes } = require("crypto");

function generateKeyPairs() {
// Generate signing key pair
const signingKeyPair = nacl.sign.keyPair();

// Generate X25519 key pair for encryption
const encryptionKeyPair = nacl.box.keyPair.fromSecretKey(
randomBytes(nacl.box.secretKeyLength)
);

return {
Signing_private_key: Buffer.from(signingKeyPair.secretKey).toString(
"base64"
),
Signing_public_key: Buffer.from(signingKeyPair.publicKey).toString(
"base64"
),
Encryption_Privatekey: Buffer.from(encryptionKeyPair.secretKey).toString(
"base64"
),
Encryption_Publickey: Buffer.from(encryptionKeyPair.publicKey).toString(
"base64"
),
};
}

// Example usage:
const keyPairs = generateKeyPairs();
console.log(keyPairs);
15 changes: 15 additions & 0 deletions utilities/signing_and_verification/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "generate-key-pairs",
"version": "1.0.0",
"description": "This Node.js script generates key pairs for signing and encryption using the `tweetnacl` and `crypto` library.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"crypto": "^1.0.1",
"tweetnacl": "^1.0.3"
}
}
50 changes: 50 additions & 0 deletions utilities/signing_and_verification/node/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Signing Key pair generation using Node.js

This Node.js script generates key pairs for signing and encryption using the `tweetnacl` and `crypto` library.

## Prerequisites

Make sure you have Node.js installed on your system. If not, you can download it from [Node.js website](https://nodejs.org/).

## Installation

```bash
npm i
```

## Usage

- Clone the repository or copy the script into your project.
- Run the script using the following command:

```bash
node index.js
```

## Output

The script will output key pairs in base64-encoded format for signing and encryption.

```bash
{
"Signing_private_key": "BASE64_ENCODED_PRIVATE_KEY",
"Signing_public_key": "BASE64_ENCODED_PUBLIC_KEY",
"Encryption_Privatekey": "BASE64_ENCODED_PRIVATE_KEY",
"Encryption_Publickey": "BASE64_ENCODED_PUBLIC_KEY"
}

```

## Example

```javascript
const keyPairs = generateKeyPairs();
console.log(keyPairs);
```

Feel free to integrate this script into your project or use it as a reference for key pair generation in Node.js.

```vbnet
Copy and paste this markdown content into a `readme.md` file in your project repository. Modify it as needed based on your project structure and additional information you want to provide.

```

0 comments on commit f45f51d

Please sign in to comment.