@cyberadityacode/simple-aes-gcm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ name: Publish to NPM
2
+ on:
3
+ release:
4
+ types: [created] # Runs when you create a "Release" on GitHub
5
+ jobs:
6
+ publish:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v4
10
+ - uses: actions/setup-node@v4
11
+ with:
12
+ node-version: '20'
13
+ registry-url: 'https://registry.npmjs.org'
14
+ - run: npm install
15
+ - run: npm publish --access public
16
+ env:
17
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aditya Dubey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # AES-GCM Crypto Library
2
+
3
+ A simple, lightweight wrapper for the Web Crypto API. Intended for Browser/Web Crypto API environments
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install simple-aes-gcm
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ import { deriveKey, encrypt, decrypt } from "simple-aes-gcm";
15
+
16
+ const key = await deriveKey("my-password", "unique-salt");
17
+ const encrypted = await encrypt("Hello World", key);
18
+ const originalText = await decrypt(encrypted, key);
19
+ ```
20
+
21
+ ## Author
22
+
23
+ Aditya Dubey
24
+ (cyberadityacode)
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@cyberadityacode/simple-aes-gcm",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight AES-GCM encryption library for the browser.",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": ["crypto", "aes-gcm", "encryption"],
11
+ "author": "Aditya Dubey",
12
+ "license": "MIT"
13
+ }
package/src/index.js ADDED
@@ -0,0 +1,65 @@
1
+ const encoder = new TextEncoder();
2
+ const decoder = new TextDecoder();
3
+
4
+ /**
5
+ * Derives a key from a password and salt.
6
+ * @param {string} password
7
+ * @param {string} salt
8
+ */
9
+ export async function deriveKey(password, salt = "default-salt") {
10
+ const baseKey = await crypto.subtle.importKey(
11
+ "raw",
12
+ encoder.encode(password),
13
+ { name: "PBKDF2" },
14
+ false,
15
+ ["deriveKey"]
16
+ );
17
+
18
+ return crypto.subtle.deriveKey(
19
+ {
20
+ name: "PBKDF2",
21
+ salt: encoder.encode(salt),
22
+ iterations: 100000,
23
+ hash: "SHA-256",
24
+ },
25
+ baseKey,
26
+ { name: "AES-GCM", length: 128 },
27
+ false,
28
+ ["encrypt", "decrypt"]
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Encrypts a string using a CryptoKey object.
34
+ */
35
+ export async function encrypt(text, key) {
36
+ const iv = crypto.getRandomValues(new Uint8Array(12));
37
+ const encrypted = await crypto.subtle.encrypt(
38
+ { name: "AES-GCM", iv },
39
+ key,
40
+ encoder.encode(text)
41
+ );
42
+
43
+ const combined = new Uint8Array(iv.length + encrypted.byteLength);
44
+ combined.set(iv);
45
+ combined.set(new Uint8Array(encrypted), iv.length);
46
+
47
+ return btoa(String.fromCharCode(...combined));
48
+ }
49
+
50
+ /**
51
+ * Decrypts a base64 string using a CryptoKey object.
52
+ */
53
+ export async function decrypt(cipherText, key) {
54
+ const data = Uint8Array.from(atob(cipherText), (c) => c.charCodeAt(0));
55
+ const iv = data.slice(0, 12);
56
+ const encrypted = data.slice(12);
57
+
58
+ const decrypted = await crypto.subtle.decrypt(
59
+ { name: "AES-GCM", iv },
60
+ key,
61
+ encrypted
62
+ );
63
+
64
+ return decoder.decode(decrypted);
65
+ }
File without changes