### CLI Usage Examples Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Examples demonstrating how to use the post-quantum helper tool from the command line. ```APIDOC ## CLI Usage Examples ### Generate Keys ```bash # Generate ML-KEM-1024 key pair (default) and save to keys.json quantum generate --output keys.json # Generate ML-KEM-768 key pair and save to keys768.json quantum generate --algorithm ML-KEM-768 --output keys768.json # Generate key pair and print to standard output quantum generate ``` --- ### Encrypt Messages ```bash # Encrypt a message from a string and save to encrypted.txt quantum encrypt --message "Hello, World!" --key keys.json --output encrypted.txt # Encrypt a message from standard input (e.g., piped from echo) and print to standard output echo "Secret" | quantum encrypt --key keys.json ``` --- ### Decrypt Messages ```bash # Decrypt a message from encrypted.txt and print to standard output quantum decrypt --input encrypted.txt --key keys.json # Decrypt a message from encrypted.txt and save to decrypted.txt quantum decrypt --input encrypted.txt --key keys.json --output decrypted.txt ``` --- ### Other Commands ```bash # Display help information for the CLI tool quantum help ``` ``` -------------------------------- ### Install @profullstack/post-quantum-helper Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Installation instructions for the post-quantum helper package using different Node.js package managers (pnpm, npm, yarn). ```bash # Using pnpm (recommended) pnpm install @profullstack/post-quantum-helper # Using npm npm install @profullstack/post-quantum-helper # Using yarn yarn add @profullstack/post-quantum-helper ``` -------------------------------- ### CLI Tool Quick Start Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Illustrates command-line interface usage for generating key pairs, encrypting, and decrypting messages with the @profullstack/post-quantum-helper tool. ```bash # Generate a key pair quantum generate --output keys.json # Encrypt a message quantum encrypt --message "Secret message" --key keys.json --output encrypted.txt # Decrypt a message quantum decrypt --input encrypted.txt --key keys.json ``` -------------------------------- ### End-to-End Encryption Example Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md JavaScript example demonstrating end-to-end encryption using the post-quantum-helper library. It shows how to generate key pairs, encrypt a message for a recipient, and decrypt it using the recipient's private key. Assumes the library is imported as '@profullstack/post-quantum-helper'. ```javascript import { generateKeyPair, encrypt, decrypt } from '@profullstack/post-quantum-helper'; // Alice generates her key pair const aliceKeys = await generateKeyPair(); // Bob generates his key pair const bobKeys = await generateKeyPair(); // Alice encrypts a message for Bob const message = 'Hello Bob!'; const encrypted = await encrypt(message, bobKeys.publicKey); // Bob decrypts Alice's message const decrypted = await decrypt(encrypted, bobKeys.privateKey); console.log(decrypted); // "Hello Bob!" ``` -------------------------------- ### Key Export and Import Example Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md JavaScript example for exporting and importing cryptographic key pairs using the post-quantum-helper library. It demonstrates generating a key pair, exporting it to a JSON format, saving it to a file, and then loading and importing it back. Requires Node.js 'fs' module. ```javascript import { generateKeyPair, exportKeyPair, importKeyPair } from '@profullstack/post-quantum-helper'; import { writeFileSync, readFileSync } from 'fs'; // Generate and export keys const keyPair = await generateKeyPair(); const exported = exportKeyPair(keyPair); // Save to file writeFileSync('keys.json', JSON.stringify(exported, null, 2)); // Load from file const loaded = JSON.JSON.parse(readFileSync('keys.json', 'utf8')); const imported = importKeyPair(loaded); ``` -------------------------------- ### Node.js Module Quick Start Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Demonstrates programmatic usage of the @profullstack/post-quantum-helper module to generate key pairs, encrypt, and decrypt messages using ML-KEM-1024. ```javascript import { generateKeyPair, encrypt, decrypt } from '@profullstack/post-quantum-helper'; // Generate a key pair const keyPair = await generateKeyPair('ML-KEM-1024'); console.log('Public Key:', keyPair.publicKey); console.log('Private Key:', keyPair.privateKey); // Encrypt a message const message = 'Hello, quantum-resistant world!'; const encrypted = await encrypt(message, keyPair.publicKey); console.log('Encrypted:', encrypted); // Decrypt the message const decrypted = await decrypt(encrypted, keyPair.privateKey); console.log('Decrypted:', decrypted); // "Hello, quantum-resistant world!" ``` -------------------------------- ### Post-Quantum Helper CLI Usage Examples (Bash) Source: https://github.com/profullstack/post-quantum-helper/blob/master/TODO.md Illustrates various command-line interface commands for the Post-Quantum Helper tool. It covers interactive mode and direct command execution for key generation, encryption, and decryption with file-based operations. ```bash # Interactive mode pqh # Direct commands pqh generate --algorithm ML-KEM-1024 pqh encrypt --message "Hello" --key public.key pqh decrypt --file encrypted.txt --key private.key ``` -------------------------------- ### Post-Quantum Helper Module API Example (JavaScript) Source: https://github.com/profullstack/post-quantum-helper/blob/master/TODO.md Demonstrates how to import and use the core functions of the Post-Quantum Helper module in a Node.js environment. It shows key generation, message encryption, and decryption using exported functions. ```javascript import { generateKeyPair, encrypt, decrypt } from 'post-quantum-helper'; // Generate keys const { publicKey, privateKey } = await generateKeyPair('ML-KEM-1024'); // Encrypt const encrypted = await encrypt(message, recipientPublicKey); // Decrypt const decrypted = await decrypt(encrypted, privateKey); ``` -------------------------------- ### Encrypting and Decrypting Multiple Messages Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md JavaScript example showing how to encrypt and decrypt an array of messages using the post-quantum-helper library. It utilizes `Promise.all` for efficient parallel processing of multiple encryption and decryption operations. This is useful for batch operations. ```javascript import { generateKeyPair, encrypt, decrypt } from '@profullstack/post-quantum-helper'; const keyPair = await generateKeyPair(); const messages = ['Message 1', 'Message 2', 'Message 3']; // Encrypt multiple messages const encrypted = await Promise.all( messages.map(msg => encrypt(msg, keyPair.publicKey)) ); // Decrypt all messages const decrypted = await Promise.all( encrypted.map(enc => decrypt(enc, keyPair.privateKey)) ); console.log(decrypted); // ['Message 1', 'Message 2', 'Message 3'] ``` -------------------------------- ### CLI: Help Command Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Displays the help information for the quantum CLI tool, outlining available commands and options. ```bash # Show help quantum help ``` -------------------------------- ### Show Project Version Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Command to display the version of the post-quantum-helper project. This is a simple utility command. ```bash quantum version ``` -------------------------------- ### Run Project Tests and Development Commands Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Bash commands for running tests, tests in watch mode, linting, and formatting the code within the post-quantum-helper project using pnpm. These commands are essential for maintaining code quality and ensuring functionality. ```bash # Run all tests pnpm test # Run tests in watch mode pnpm test:watch # Run linter pnpm lint # Format code pnpm format ``` -------------------------------- ### CLI: Generate Keys Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Command-line options for generating ML-KEM key pairs, specifying algorithms and output destinations, including stdout. ```bash # Generate ML-KEM-1024 key pair (default) quantum generate --output keys.json # Generate ML-KEM-768 key pair quantum generate --algorithm ML-KEM-768 --output keys768.json # Output to stdout quantum generate ``` -------------------------------- ### Generate Key Pair (Module API) Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md API reference for generating a post-quantum key pair using the `generateKeyPair` function. Supports different ML-KEM algorithms. ```javascript const keyPair = await generateKeyPair('ML-KEM-1024'); // Returns: { publicKey: string, privateKey: string, algorithm: string } ``` -------------------------------- ### Crypto Utilities Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Provides utility classes for Base64 encoding/decoding and secure random number generation. ```APIDOC ## Crypto Utilities ### `Base64` Utilities for Base64 encoding and decoding. #### Methods - **`encode(uint8Array)`**: Encodes a `Uint8Array` into a Base64 string. - **`decode(base64String)`**: Decodes a Base64 string into a `Uint8Array`. --- ### `SecureRandom` Provides functions for generating cryptographically secure random data. #### Methods - **`getRandomBytes(length)`**: Generates an array of random bytes of the specified `length`. - **`generateSalt()`**: Generates a random salt, typically used in hashing functions. - **`generateNonce()`**: Generates a cryptographically secure nonce (number used once). ``` -------------------------------- ### Import Key Pair (Module API) Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md API reference for importing a key pair from exported data using the `importKeyPair` function. ```javascript const keyPair = importKeyPair(exportedData); ``` -------------------------------- ### Key Management API Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Functions for generating, exporting, importing, and validating cryptographic key pairs. ```APIDOC ## Key Management API ### `generateKeyPair(algorithm?)` Generate a new post-quantum key pair. #### Parameters - **algorithm** (string, optional): Specifies the encryption algorithm. Accepts `'ML-KEM-1024'` (default) or `'ML-KEM-768'`. #### Returns - `Promise<{ publicKey: string, privateKey: string, algorithm: string }>`: A promise that resolves to an object containing the public key, private key, and the algorithm used. --- ### `exportKeyPair(keyPair)` Export a key pair with metadata for secure storage. #### Parameters - **keyPair** (object): The key pair object generated by `generateKeyPair`. #### Returns - `object`: An object containing the exported key pair along with metadata like timestamp and version. --- ### `importKeyPair(data)` Import a key pair from exported data. #### Parameters - **data** (object): The data object exported by `exportKeyPair`. #### Returns - `object`: The imported key pair object. --- ### `validatePublicKey(publicKey, algorithm?)` Validate the format and size of a public key. #### Parameters - **publicKey** (string): The public key string to validate. - **algorithm** (string, optional): The algorithm associated with the public key. #### Returns - `boolean`: `true` if the public key is valid, `false` otherwise. ``` -------------------------------- ### CLI: Encrypt Messages Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Command-line options for encrypting messages, specifying the message content, key file, and output destination (file or stdout). ```bash # Encrypt a message quantum encrypt --message "Hello, World!" --key keys.json --output encrypted.txt # Encrypt from stdin (output to stdout) echo "Secret" | quantum encrypt --key keys.json ``` -------------------------------- ### Export Key Pair (Module API) Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md API reference for exporting a key pair with metadata using the `exportKeyPair` function, suitable for storage. ```javascript const exported = exportKeyPair(keyPair); // Returns: { publicKey, privateKey, algorithm, timestamp, version } ``` -------------------------------- ### Validate Public Key (Module API) Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md API reference for validating the format and size of a public key using the `validatePublicKey` function. ```javascript const isValid = validatePublicKey(publicKey, 'ML-KEM-1024'); // Returns: boolean ``` -------------------------------- ### CLI: Decrypt Messages Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Command-line options for decrypting messages, specifying the input encrypted file, key file, and output destination (console or file). ```bash # Decrypt a message quantum decrypt --input encrypted.txt --key keys.json # Decrypt to file quantum decrypt --input encrypted.txt --key keys.json --output decrypted.txt ``` -------------------------------- ### Encrypt Message (Module API) Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md API reference for encrypting a message using the `encrypt` function, requiring the message and recipient's public key. ```javascript const encrypted = await encrypt( 'Secret message', recipientPublicKey, 'ML-KEM-1024' ); ``` -------------------------------- ### Base64 Utilities (Module API) Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Provides Base64 encoding and decoding utilities within the module for byte array manipulation. ```javascript import { Base64 } from '@profullstack/post-quantum-helper'; const encoded = Base64.encode(new Uint8Array([1, 2, 3])); const decoded = Base64.decode(encoded); ``` -------------------------------- ### Secure Random Generation (Module API) Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Offers cryptographically secure random number generation utilities, including generating random bytes, salts, and nonces. ```javascript import { SecureRandom } from '@profullstack/post-quantum-helper'; const randomBytes = SecureRandom.getRandomBytes(32); const salt = SecureRandom.generateSalt(); const nonce = SecureRandom.generateNonce(); ``` -------------------------------- ### Encryption & Decryption API Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md Functions for encrypting messages to a recipient's public key and decrypting messages using a private key. ```APIDOC ## Encryption & Decryption API ### `encrypt(message, recipientPublicKey, algorithm?)` Encrypt a message intended for a specific recipient using their public key. #### Parameters - **message** (string): The plaintext message to be encrypted. - **recipientPublicKey** (string): The recipient's public key, typically in Base64 format. - **algorithm** (string, optional): The encryption algorithm to use. If not provided, it may be inferred or use a default. #### Returns - `Promise`: A promise that resolves to a JSON string representing the encrypted message. --- ### `decrypt(encryptedContent, privateKey, algorithm?)` Decrypt an encrypted message using the corresponding private key. #### Parameters - **encryptedContent** (string): The encrypted message, usually a JSON string generated by the `encrypt` function. - **privateKey** (string): The private key (typically Base64 encoded) required for decryption. - **algorithm** (string, optional): The algorithm used for encryption. If not provided, the function attempts to auto-detect it from the `encryptedContent`. #### Returns - `Promise`: A promise that resolves to the original decrypted message string. ``` -------------------------------- ### Decrypt Message (Module API) Source: https://github.com/profullstack/post-quantum-helper/blob/master/README.md API reference for decrypting a message using the `decrypt` function, requiring the encrypted content and the private key. ```javascript const decrypted = await decrypt(encrypted, privateKey); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.