simple-hpke 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +14 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -78,6 +78,8 @@ const aesKey = await crypto.subtle.generateKey(
78
78
  // Wrap an existing key.
79
79
  const { enc: sealedKey } = await seal(keypair, aesKey)
80
80
 
81
+ // or pass in just a public key
82
+
81
83
  // Later, recover the same key with your private key.
82
84
  const recoveredKey = await open(keypair, sealedKey)
83
85
 
@@ -115,19 +117,22 @@ const ciphertextBuffer = await crypto.subtle.encrypt(
115
117
  new TextEncoder().encode('attack at dawn')
116
118
  )
117
119
 
118
- // Send `enc`, `iv`, and `ciphertext` together. `enc` is a fixed
119
- // 80 bytes for this suite, and the AES-GCM IV is 12 bytes, so the recipient
120
- // can slice the payload back apart at known offsets.
120
+ // Send `enc`, `iv`, and `ciphertext` together. `create(...)` defaults to a
121
+ // 256-bit AES key, so `enc.length` is 80 bytes in this example.
122
+ //
123
+ // If your protocol allows different wrapped-key sizes, prefix `enc.length`
124
+ // (or otherwise transmit it) so the recipient can split the payload safely.
121
125
  const ciphertext = new Uint8Array(ciphertextBuffer)
122
- const message = new Uint8Array(enc.length + iv.length + ciphertext.length)
126
+ const encLength = enc.length
127
+ const message = new Uint8Array(encLength + iv.length + ciphertext.length)
123
128
  message.set(enc, 0)
124
- message.set(iv, enc.length)
125
- message.set(ciphertext, enc.length + iv.length)
129
+ message.set(iv, encLength)
130
+ message.set(ciphertext, encLength + iv.length)
126
131
 
127
132
  // On the other side, split the payload back into its parts.
128
- const enc2 = message.subarray(0, 80)
129
- const iv2 = message.subarray(80, 80 + 12)
130
- const ciphertext2 = message.subarray(80 + 12)
133
+ const enc2 = message.subarray(0, encLength)
134
+ const iv2 = message.subarray(encLength, encLength + 12)
135
+ const ciphertext2 = message.subarray(encLength + 12)
131
136
 
132
137
  // Recover the key, then decrypt the message.
133
138
  const recovered = await open(recipient, enc2)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-hpke",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Hybrid Public Key Encryption",
5
5
  "type": "module",
6
6
  "files": [