{"id":31038999,"url":"https://github.com/tigthor/encyption","last_synced_at":"2026-04-27T16:31:52.269Z","repository":{"id":311240472,"uuid":"1042999119","full_name":"tigthor/encyption","owner":"tigthor","description":"�� Simple and secure encryption/decryption utility for TypeScript applications. Works seamlessly with backend APIs and frontend Next.js applications.","archived":false,"fork":false,"pushed_at":"2025-08-23T00:12:51.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-12T15:35:36.920Z","etag":null,"topics":["aes","browser","crypto","encryption","javascript","nextjs","nodejs","security","typescript","utils"],"latest_commit_sha":null,"homepage":null,"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/tigthor.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-08-23T00:11:35.000Z","updated_at":"2025-08-23T00:13:05.000Z","dependencies_parsed_at":"2025-08-23T02:38:43.332Z","dependency_job_id":"8fa63aee-9f04-4980-9ede-1957075c3718","html_url":"https://github.com/tigthor/encyption","commit_stats":null,"previous_names":["tigthor/encyption"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tigthor/encyption","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigthor%2Fencyption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigthor%2Fencyption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigthor%2Fencyption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigthor%2Fencyption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tigthor","download_url":"https://codeload.github.com/tigthor/encyption/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigthor%2Fencyption/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275076535,"owners_count":25401314,"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-09-14T02:00:10.474Z","response_time":75,"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":["aes","browser","crypto","encryption","javascript","nextjs","nodejs","security","typescript","utils"],"created_at":"2025-09-14T07:44:54.927Z","updated_at":"2026-04-27T16:31:52.234Z","avatar_url":"https://github.com/tigthor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @tigthor/encyption-utils\n\n[![npm version](https://badge.fury.io/js/@tigthor%2Fencyption-utils.svg)](https://badge.fury.io/js/@tigthor%2Fencyption-utils)\n[![GitHub](https://img.shields.io/github/license/tigthor/encyption)](https://github.com/tigthor/encyption/blob/main/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/tigthor/encyption)](https://github.com/tigthor/encyption/stargazers)\n[![GitHub issues](https://img.shields.io/github/issues/tigthor/encyption)](https://github.com/tigthor/encyption/issues)\n\nA simple, secure, and easy-to-use encryption/decryption utility for TypeScript applications. Works seamlessly with both backend APIs and frontend Next.js applications.\n\n## 📦 Installation\n\n```bash\nnpm install @tigthor/encyption-utils\n```\n\n```bash\npnpm add @tigthor/encyption-utils\n```\n\n```bash\nyarn add @tigthor/encyption-utils\n```\n\n## Features\n\n- 🔐 **Secure AES Encryption**: Uses AES-256-CBC encryption with PBKDF2 key derivation\n- 🚀 **Easy to Use**: Simple API with both basic and advanced usage patterns\n- 🔧 **Configurable**: Customizable encryption parameters\n- 🌍 **Universal**: Works in both Node.js and browser environments\n- 📝 **TypeScript**: Full TypeScript support with type definitions\n- 🧪 **Well Tested**: Comprehensive test coverage\n- 📦 **Lightweight**: Minimal dependencies\n\n## Installation\n\n```bash\nnpm install @tigthor/encyption-utils\n```\n\n## Quick Start\n\n### Basic Usage\n\n```typescript\nimport { quickEncrypt, quickDecrypt } from '@tigthor/encyption-utils';\n\n// Encrypt\nconst encrypted = quickEncrypt('Hello, World!', 'my-secret-password');\nconsole.log(encrypted); // \"salt:iv:encryptedData\"\n\n// Decrypt\nconst decrypted = quickDecrypt(encrypted, 'my-secret-password');\nconsole.log(decrypted); // \"Hello, World!\"\n```\n\n### Advanced Usage with EncryptionManager\n\n```typescript\nimport { EncryptionManager } from '@tigthor/encyption-utils';\n\n// Create an instance with configuration\nconst crypto = new EncryptionManager({\n  secretKey: 'your-app-secret-key',\n  defaultOptions: {\n    iterations: 10000,\n    keySize: 256,\n  },\n});\n\n// Encrypt using the configured secret key\nconst encrypted = crypto.encryptSimple('Sensitive data');\nconst decrypted = crypto.decryptSimple(encrypted);\n\n// Or encrypt with a specific password\nconst result = crypto.encrypt('Data to encrypt', 'specific-password');\nconst original = crypto.decrypt(result, 'specific-password');\n```\n\n### Global Instance Pattern\n\n```typescript\nimport { initializeEncryption, encrypt, decrypt } from '@tigthor/encyption-utils';\n\n// Initialize once in your app\ninitializeEncryption({ secretKey: 'your-global-secret' });\n\n// Use anywhere in your app\nconst encrypted = encrypt('My secret message');\nconst decrypted = decrypt(encrypted);\n```\n\n## Usage Examples\n\n### Backend API (Express.js)\n\n```typescript\nimport express from 'express';\nimport { EncryptionManager } from '@tigthor/encyption-utils';\n\nconst app = express();\nconst crypto = new EncryptionManager({ secretKey: process.env.ENCRYPTION_KEY });\n\napp.post('/api/secure-data', (req, res) =\u003e {\n  const sensitiveData = req.body.data;\n  \n  // Encrypt before storing in database\n  const encrypted = crypto.encryptSimple(JSON.stringify(sensitiveData));\n  \n  // Store encrypted data...\n  res.json({ success: true });\n});\n\napp.get('/api/secure-data/:id', (req, res) =\u003e {\n  // Retrieve encrypted data from database...\n  const encryptedData = getFromDatabase(req.params.id);\n  \n  // Decrypt before sending\n  const decrypted = JSON.parse(crypto.decryptSimple(encryptedData));\n  \n  res.json({ data: decrypted });\n});\n```\n\n### Frontend Next.js\n\n```typescript\n// utils/crypto.ts\nimport { createEncryption } from '@tigthor/encyption-utils';\n\nexport const crypto = createEncryption({ \n  secretKey: process.env.NEXT_PUBLIC_ENCRYPTION_KEY \n});\n\n// components/SecureForm.tsx\nimport { useState } from 'react';\nimport { crypto } from '../utils/crypto';\n\nexport default function SecureForm() {\n  const [data, setData] = useState('');\n\n  const handleSubmit = async () =\u003e {\n    // Encrypt data before sending to API\n    const encrypted = crypto.encryptSimple(data);\n    \n    await fetch('/api/secure-endpoint', {\n      method: 'POST',\n      headers: { 'Content-Type': 'application/json' },\n      body: JSON.stringify({ encryptedData: encrypted }),\n    });\n  };\n\n  return (\n    \u003cform onSubmit={handleSubmit}\u003e\n      \u003cinput \n        value={data} \n        onChange={(e) =\u003e setData(e.target.value)}\n        placeholder=\"Enter sensitive data\"\n      /\u003e\n      \u003cbutton type=\"submit\"\u003eSubmit Securely\u003c/button\u003e\n    \u003c/form\u003e\n  );\n}\n```\n\n### Environment Variables\n\n```bash\n# .env\nENCRYPTION_KEY=your-super-secret-encryption-key-here\n\n# .env.local (Next.js)\nNEXT_PUBLIC_ENCRYPTION_KEY=your-frontend-encryption-key\n```\n\n## API Reference\n\n### EncryptionManager\n\nThe main class for encryption operations.\n\n```typescript\nconstructor(config?: CryptoConfig)\n```\n\n**Methods:**\n- `encrypt(plaintext: string, password?: string, options?: EncryptionOptions): EncryptionResult`\n- `decrypt(encryptedData: string | EncryptionResult, password?: string, options?: DecryptionOptions): string`\n- `encryptSimple(plaintext: string): string`\n- `decryptSimple(encryptedString: string): string`\n- `setSecretKey(key: string): void`\n- `updateConfig(newConfig: Partial\u003cCryptoConfig\u003e): void`\n\n### Quick Functions\n\nConvenient functions for simple use cases:\n\n```typescript\nquickEncrypt(plaintext: string, password: string): string\nquickDecrypt(encryptedString: string, password: string): string\n```\n\n### Factory Functions\n\n```typescript\ncreateEncryption(config?: CryptoConfig): EncryptionManager\ninitializeEncryption(config: CryptoConfig): EncryptionManager\ngetEncryption(): EncryptionManager\n```\n\n### Utility Functions\n\n```typescript\ngenerateRandomKey(length?: number): string\ngenerateSalt(length?: number): string\ngenerateIV(length?: number): string\nhashString(input: string): string\ngenerateHMAC(message: string, key: string): string\nverifyHMAC(message: string, key: string, signature: string): boolean\n```\n\n## Configuration Options\n\n```typescript\ninterface CryptoConfig {\n  secretKey?: string;\n  defaultOptions?: EncryptionOptions;\n}\n\ninterface EncryptionOptions {\n  algorithm?: string;    // Default: 'AES'\n  keySize?: number;      // Default: 256\n  iterations?: number;   // Default: 10000\n}\n```\n\n## Security Best Practices\n\n1. **Use Environment Variables**: Never hardcode encryption keys in your source code\n2. **Strong Keys**: Use long, random keys (at least 32 characters)\n3. **Key Rotation**: Regularly rotate your encryption keys\n4. **HTTPS**: Always use HTTPS when transmitting encrypted data\n5. **Backend Validation**: Always validate and sanitize data on the backend\n\n## Error Handling\n\nThe library throws descriptive errors for common issues:\n\n```typescript\ntry {\n  const encrypted = crypto.encryptSimple('data');\n  const decrypted = crypto.decryptSimple(encrypted);\n} catch (error) {\n  console.error('Encryption error:', error.message);\n}\n```\n\n## Browser Compatibility\n\nWorks in all modern browsers that support:\n- ES2020+\n- Web Crypto API (for secure random number generation)\n\n## Node.js Compatibility\n\n- Node.js 16+\n- Supports both CommonJS and ES Modules\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch: `git checkout -b feature/new-feature`\n3. Make changes and add tests\n4. Run tests: `npm test`\n5. Commit changes: `git commit -am 'Add new feature'`\n6. Push to branch: `git push origin feature/new-feature`\n7. Submit a pull request\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Changelog\n\n### 1.0.0\n- Initial release\n- AES-256-CBC encryption\n- PBKDF2 key derivation\n- TypeScript support\n- Browser and Node.js compatibility\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigthor%2Fencyption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftigthor%2Fencyption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigthor%2Fencyption/lists"}