{"id":29966456,"url":"https://github.com/deviai-opensource/asymmetric-cryptography-data-exchange-utils","last_synced_at":"2025-08-04T03:02:53.297Z","repository":{"id":306554205,"uuid":"1026576609","full_name":"DeviAI-OpenSource/asymmetric-cryptography-data-exchange-utils","owner":"DeviAI-OpenSource","description":"A clean, modern asymmetric cryptography library using Web Crypto API - universally compatible with Node.js, browsers, Cloudflare Workers, Deno, and Bun","archived":false,"fork":false,"pushed_at":"2025-07-26T07:07:36.000Z","size":72,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-26T12:29:32.800Z","etag":null,"topics":["asymmetric","browser","bun","clean-api","cloudflare-workers","crypto","data-exchange","deno","encryption","modern","rsa","security","universal","web-crypto"],"latest_commit_sha":null,"homepage":"https://deviai-opensource.github.io/asymmetric-cryptography-data-exchange-utils/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeviAI-OpenSource.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-26T06:56:24.000Z","updated_at":"2025-07-26T09:38:41.000Z","dependencies_parsed_at":"2025-07-26T12:41:30.174Z","dependency_job_id":null,"html_url":"https://github.com/DeviAI-OpenSource/asymmetric-cryptography-data-exchange-utils","commit_stats":null,"previous_names":["deviai-opensource/asymmetric-cryptography-data-exchange-utils"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/DeviAI-OpenSource/asymmetric-cryptography-data-exchange-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeviAI-OpenSource%2Fasymmetric-cryptography-data-exchange-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeviAI-OpenSource%2Fasymmetric-cryptography-data-exchange-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeviAI-OpenSource%2Fasymmetric-cryptography-data-exchange-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeviAI-OpenSource%2Fasymmetric-cryptography-data-exchange-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeviAI-OpenSource","download_url":"https://codeload.github.com/DeviAI-OpenSource/asymmetric-cryptography-data-exchange-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeviAI-OpenSource%2Fasymmetric-cryptography-data-exchange-utils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268643724,"owners_count":24283314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asymmetric","browser","bun","clean-api","cloudflare-workers","crypto","data-exchange","deno","encryption","modern","rsa","security","universal","web-crypto"],"created_at":"2025-08-04T03:00:55.530Z","updated_at":"2025-08-04T03:02:53.279Z","avatar_url":"https://github.com/DeviAI-OpenSource.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Universal Asymmetric Cryptography Data Exchange Utils\n\nA comprehensive TypeScript library for asymmetric cryptography operations using the **Web Crypto API**. This library provides easy-to-use functions for RSA key generation, encryption, and decryption that work **universally** across all modern JavaScript runtimes.\n\n## 🌍 Universal Compatibility\n\n✅ **Node.js** 16+ (with Web Crypto API)  \n✅ **Browsers** (Chrome, Firefox, Safari, Edge)  \n✅ **Cloudflare Workers**  \n✅ **Deno**  \n✅ **Bun**  \n✅ **Web Workers \u0026 Service Workers**\n\n## Features\n\n- 🔐 **RSA Key Pair Generation**: Create public and private key pairs (CryptoKey \u0026 PEM formats)\n- 🔒 **Public Key Encryption**: Encrypt data using public keys (RSA-OAEP)\n- 🔓 **Private Key Decryption**: Decrypt data using private keys\n- 📦 **TypeScript Support**: Full TypeScript support with type definitions\n- 🚀 **Multiple Formats**: CommonJS and ES Module support\n- 🛡️ **Secure**: Uses Web Crypto API with industry-standard algorithms\n- ⚡ **Async/Promise-based**: Modern async API for better performance\n\n## Installation\n\n```bash\nnpm install asymmetric-cryptography-data-exchange-utils\n```\n\n## Quick Start\n\n### Modern Web Crypto API (CryptoKey format)\n\n```typescript\nimport {\n  createKeys,\n  encryptWithPubKey,\n  decryptWithPrivateKey,\n} from \"asymmetric-cryptography-data-exchange-utils\";\n\n// 1. Generate a key pair (CryptoKey format)\nconst keyPair = await createKeys(2048);\n\n// 2. Encrypt with public key, decrypt with private key\nconst message = \"Hello, World!\";\nconst encrypted = await encryptWithPubKey(message, keyPair.publicKey);\nconst decrypted = await decryptWithPrivateKey(encrypted, keyPair.privateKey);\n\nconsole.log(decrypted); // \"Hello, World!\"\n```\n\n### PEM Format (Node.js-style compatibility)\n\n```typescript\nimport {\n  createKeysPEM,\n  encryptWithPubKeyPEM,\n  decryptWithPrivateKeyPEM,\n} from \"asymmetric-cryptography-data-exchange-utils\";\n\n// 1. Generate a key pair (PEM format)\nconst keyPair = await createKeysPEM(2048);\n\n// 2. Encrypt with public key PEM, decrypt with private key PEM\nconst message = \"Hello, World!\";\nconst encrypted = await encryptWithPubKeyPEM(message, keyPair.publicKey);\nconst decrypted = await decryptWithPrivateKeyPEM(encrypted, keyPair.privateKey);\n\nconsole.log(decrypted); // \"Hello, World!\"\n```\n\n## API Reference\n\n### CryptoKey API (Recommended)\n\n#### `createKeys(keySize?: number): Promise\u003cKeyPair\u003e`\n\nCreates a new RSA key pair using Web Crypto API.\n\n**Parameters:**\n\n- `keySize` (optional): The size of the key in bits. Default: 2048\n\n**Returns:**\n\n- `Promise\u003cKeyPair\u003e`: Object containing `publicKey` and `privateKey` as CryptoKey objects\n\n**Example:**\n\n```typescript\nconst keyPair = await createKeys(2048);\nconsole.log(keyPair.publicKey.type); // \"public\"\nconsole.log(keyPair.publicKey.algorithm); // { name: \"RSA-OAEP\", ... }\n```\n\n#### `encryptWithPubKey(data: string | ArrayBuffer, publicKey: CryptoKey): Promise\u003cEncryptedData\u003e`\n\nEncrypts data using a public CryptoKey (RSA-OAEP padding).\n\n**Parameters:**\n\n- `data`: The string or ArrayBuffer data to encrypt\n- `publicKey`: The public CryptoKey\n\n**Returns:**\n\n- `Promise\u003cEncryptedData\u003e`: Object with encrypted ArrayBuffer data\n\n**Example:**\n\n```typescript\nconst encrypted = await encryptWithPubKey(\"secret message\", keyPair.publicKey);\nconsole.log(encrypted.data); // ArrayBuffer\n```\n\n#### `decryptWithPrivateKey(encryptedData: EncryptedData, privateKey: CryptoKey): Promise\u003cstring\u003e`\n\nDecrypts data using a private CryptoKey.\n\n**Parameters:**\n\n- `encryptedData`: The encrypted data object\n- `privateKey`: The private CryptoKey\n\n**Returns:**\n\n- `Promise\u003cstring\u003e`: The decrypted message\n\n### PEM API\n\n#### `createKeysPEM(keySize?: number): Promise\u003cKeyPairPEM\u003e`\n\nCreates a new RSA key pair and exports them as PEM strings.\n\n**Returns:**\n\n- `Promise\u003cKeyPairPEM\u003e`: Object containing `publicKey` and `privateKey` as PEM strings\n\n#### `encryptWithPubKeyPEM(data: string, publicKeyPEM: string): Promise\u003c{data: string, encoding: 'base64'}\u003e`\n\nEncrypts data using a public key PEM string.\n\n#### `decryptWithPrivateKeyPEM(encryptedData: {data: string, encoding: 'base64'}, privateKeyPEM: string): Promise\u003cstring\u003e`\n\nDecrypts data using a private key PEM string.\n\n## Type Definitions\n\n```typescript\ninterface KeyPair {\n  publicKey: CryptoKey;\n  privateKey: CryptoKey;\n}\n\ninterface KeyPairPEM {\n  publicKey: string;\n  privateKey: string;\n}\n\ninterface EncryptedData {\n  data: ArrayBuffer;\n}\n```\n\n## Platform-Specific Usage\n\n### Node.js\n\n```typescript\nimport { createKeys } from \"asymmetric-cryptography-data-exchange-utils\";\n\n// Works with Node.js 16+ Web Crypto API\nconst keyPair = await createKeys();\n```\n\n### Browser\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { createKeys } from \"https://esm.sh/asymmetric-cryptography-data-exchange-utils\";\n\n  const keyPair = await createKeys();\n  console.log(\"Crypto in browser!\", keyPair);\n\u003c/script\u003e\n```\n\n### Cloudflare Workers\n\n```typescript\n// worker.js\nimport {\n  createKeys,\n  encryptWithPubKey,\n} from \"asymmetric-cryptography-data-exchange-utils\";\n\nexport default {\n  async fetch(request, env, ctx) {\n    const keyPair = await createKeys();\n    const encrypted = await encryptWithPubKey(\n      \"Hello from CF Workers!\",\n      keyPair.publicKey\n    );\n\n    return new Response(\n      JSON.stringify({\n        success: true,\n        keyType: keyPair.publicKey.type,\n      })\n    );\n  },\n};\n```\n\n### Deno\n\n```typescript\nimport { createKeys } from \"npm:asymmetric-cryptography-data-exchange-utils\";\n\nconst keyPair = await createKeys();\nconsole.log(\"Crypto in Deno!\", keyPair.publicKey.type);\n```\n\n## Common Use Cases\n\n### 1. Secure Message Exchange\n\n```typescript\n// Alice creates a key pair\nconst aliceKeys = await createKeys();\n\n// Bob encrypts a message for Alice using her public key\nconst message = \"Secret information for Alice\";\nconst encrypted = await encryptWithPubKey(message, aliceKeys.publicKey);\n\n// Alice decrypts the message using her private key\nconst decrypted = await decryptWithPrivateKey(encrypted, aliceKeys.privateKey);\n```\n\n### 2. Cross-Platform Data Exchange\n\n```typescript\n// Server (Node.js) generates keys\nconst serverKeys = await createKeysPEM();\n\n// Send public key to client (browser/worker)\n// Client encrypts data\nconst clientData = await encryptWithPubKeyPEM(\n  \"sensitive data\",\n  serverKeys.publicKey\n);\n\n// Server decrypts\nconst serverDecrypted = await decryptWithPrivateKeyPEM(\n  clientData,\n  serverKeys.privateKey\n);\n```\n\n## Development\n\n### Testing\n\n```bash\n# Run all tests\nnpm test\n\n# Run tests in watch mode\nnpm run test:watch\n\n# Run tests with coverage\nnpm run test:coverage\n```\n\nThe library includes comprehensive Jest tests with high code coverage, testing all cryptographic operations, error handling, and edge cases across different API formats.\n\n### Example Usage\n\n```bash\n# Run the basic usage example\nnpm run example\n```\n\n## Security Notes\n\n- **Key Size**: Use at least 2048 bits for production use (4096 bits recommended for high security)\n- **Algorithm**: Uses RSA-OAEP with SHA-256 for encryption\n- **Key Storage**: Store private keys securely and never expose them in client-side code\n- **Message Size**: RSA encryption has size limits based on key size and padding (~190 bytes for 2048-bit keys)\n- **Performance**: Key generation is computationally expensive; consider caching keys when appropriate\n\n## Platform Compatibility Matrix\n\n| Platform           | Web Crypto API | CryptoKey Support | PEM Support | Status       |\n| ------------------ | -------------- | ----------------- | ----------- | ------------ |\n| Node.js 16+        | ✅             | ✅                | ✅          | Full Support |\n| Chrome/Edge        | ✅             | ✅                | ✅          | Full Support |\n| Firefox            | ✅             | ✅                | ✅          | Full Support |\n| Safari             | ✅             | ✅                | ✅          | Full Support |\n| Cloudflare Workers | ✅             | ✅                | ✅          | Full Support |\n| Deno               | ✅             | ✅                | ✅          | Full Support |\n| Bun                | ✅             | ✅                | ✅          | Full Support |\n| Web Workers        | ✅             | ✅                | ✅          | Full Support |\n\n## Migration from Node.js crypto\n\nIf you're migrating from the Node.js `crypto` module:\n\n### Before (Node.js crypto)\n\n```typescript\nimport { generateKeyPairSync, publicEncrypt, privateDecrypt } from \"crypto\";\n\nconst { publicKey, privateKey } = generateKeyPairSync(\"rsa\", {\n  modulusLength: 2048,\n  publicKeyEncoding: { type: \"spki\", format: \"pem\" },\n  privateKeyEncoding: { type: \"pkcs8\", format: \"pem\" },\n});\n\nconst encrypted = publicEncrypt(publicKey, Buffer.from(message));\nconst decrypted = privateDecrypt(privateKey, encrypted).toString();\n```\n\n### After (Universal Web Crypto)\n\n```typescript\nimport {\n  createKeysPEM,\n  encryptWithPubKeyPEM,\n  decryptWithPrivateKeyPEM,\n} from \"asymmetric-cryptography-data-exchange-utils\";\n\nconst { publicKey, privateKey } = await createKeysPEM(2048);\n\nconst encrypted = await encryptWithPubKeyPEM(message, publicKey);\nconst decrypted = await decryptWithPrivateKeyPEM(encrypted, privateKey);\n```\n\n## Requirements\n\n- Node.js \u003e= 16.0.0 (for Web Crypto API support)\n- Modern browsers with Web Crypto API support\n- TypeScript (for development)\n\n## Scripts\n\n- `npm run build` - Build the library for production\n- `npm run dev` - Build in watch mode for development\n- `npm test` - Run Jest tests\n- `npm run test:watch` - Run tests in watch mode\n- `npm run test:coverage` - Run tests with coverage report\n- `npm run example` - Run the usage example\n\n## License\n\nMIT\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeviai-opensource%2Fasymmetric-cryptography-data-exchange-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeviai-opensource%2Fasymmetric-cryptography-data-exchange-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeviai-opensource%2Fasymmetric-cryptography-data-exchange-utils/lists"}