-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
332 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,38 +114,36 @@ This section shows some typical usage examples. | |
import { Chacha20Poly1305 } from "https://esm.sh/@hpke/[email protected]"; | ||
globalThis.doHpke = async () => { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemP256HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Chacha20Poly1305() | ||
}); | ||
try { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemP256HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Chacha20Poly1305() | ||
}); | ||
const rkp = await suite.kem.generateKeyPair(); | ||
const rkp = await suite.kem.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey | ||
}); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also acceptable. | ||
enc: sender.enc, | ||
}); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey | ||
}); | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("hello world!")); | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
// decrypt | ||
try { | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also acceptable. | ||
enc: sender.enc, | ||
}); | ||
// decrypt | ||
const pt = await recipient.open(ct); | ||
// hello world! | ||
// Hello world! | ||
alert(new TextDecoder().decode(pt)); | ||
} catch (err) { | ||
alert("failed to decrypt."); | ||
alert("failed:", err.message); | ||
} | ||
} | ||
</script> | ||
<button type="button" onclick="doHpke()">do HPKE</button> | ||
</body> | ||
|
@@ -173,26 +171,26 @@ async function doHpke() { | |
recipientPublicKey: rkp.publicKey, | ||
}); | ||
|
||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
|
||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, | ||
enc: sender.enc, | ||
}); | ||
|
||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("my-secret-message")); | ||
|
||
// decrypt | ||
try { | ||
const pt = await recipient.open(ct); | ||
|
||
console.log("decrypted: ", new TextDecoder().decode(pt)); | ||
// decrypted: my-secret-message | ||
} catch (err) { | ||
console.log("failed to decrypt."); | ||
} | ||
const pt = await recipient.open(ct); | ||
|
||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
|
||
doHpke(); | ||
try { | ||
doHpke(); | ||
} catch (err) { | ||
console.log("failed:", err.message); | ||
} | ||
``` | ||
|
||
### Deno | ||
|
@@ -217,26 +215,26 @@ async function doHpke() { | |
recipientPublicKey: rkp.publicKey, | ||
}); | ||
|
||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
|
||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, | ||
enc: sender.enc, | ||
}); | ||
|
||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("my-secret-message")); | ||
|
||
try { | ||
// decrypt | ||
const pt = await recipient.open(ct); | ||
// decrypt | ||
const pt = await recipient.open(ct); | ||
|
||
console.log("decrypted: ", new TextDecoder().decode(pt)); | ||
// decrypted: my-secret-message | ||
} catch (_err: unknown) { | ||
console.log("failed to decrypt."); | ||
} | ||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
|
||
doHpke(); | ||
try { | ||
doHpke(); | ||
} catch (_err: unknown) { | ||
console.log("failed."); | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,38 +111,36 @@ This section shows some typical usage examples. | |
import { DhkemSecp256k1HkdfSha256 } from "https://esm.sh/@hpke/[email protected]"; | ||
globalThis.doHpke = async () => { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemSecp256k1HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Aes128Gcm(), | ||
}); | ||
try { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemSecp256k1HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Aes128Gcm(), | ||
}); | ||
const rkp = await suite.kem.generateKeyPair(); | ||
const rkp = await suite.kem.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey | ||
}); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also acceptable. | ||
enc: sender.enc, | ||
}); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey | ||
}); | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("hello world!")); | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
// decrypt | ||
try { | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also acceptable. | ||
enc: sender.enc, | ||
}); | ||
// decrypt | ||
const pt = await recipient.open(ct); | ||
// hello world! | ||
// Hello world! | ||
alert(new TextDecoder().decode(pt)); | ||
} catch (err) { | ||
alert("failed to decrypt."); | ||
alert("failed:", err.message); | ||
} | ||
} | ||
</script> | ||
<button type="button" onclick="doHpke()">do HPKE</button> | ||
</body> | ||
|
@@ -170,26 +168,26 @@ async function doHpke() { | |
recipientPublicKey: rkp.publicKey, | ||
}); | ||
|
||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
|
||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, | ||
enc: sender.enc, | ||
}); | ||
|
||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("my-secret-message")); | ||
|
||
// decrypt | ||
try { | ||
const pt = await recipient.open(ct); | ||
|
||
console.log("decrypted: ", new TextDecoder().decode(pt)); | ||
// decrypted: my-secret-message | ||
} catch (err) { | ||
console.log("failed to decrypt."); | ||
} | ||
const pt = await recipient.open(ct); | ||
|
||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
|
||
doHpke(); | ||
try { | ||
doHpke(); | ||
} catch (err) { | ||
console.log("failed:", err.message); | ||
} | ||
``` | ||
|
||
### Deno | ||
|
@@ -212,26 +210,26 @@ async function doHpke() { | |
recipientPublicKey: rkp.publicKey, | ||
}); | ||
|
||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
|
||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, | ||
enc: sender.enc, | ||
}); | ||
|
||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("my-secret-message")); | ||
|
||
try { | ||
// decrypt | ||
const pt = await recipient.open(ct); | ||
// decrypt | ||
const pt = await recipient.open(ct); | ||
|
||
console.log("decrypted: ", new TextDecoder().decode(pt)); | ||
// decrypted: my-secret-message | ||
} catch (_err: unknown) { | ||
console.log("failed to decrypt."); | ||
} | ||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
|
||
doHpke(); | ||
try { | ||
doHpke(); | ||
} catch (_err: unknown) { | ||
console.log("failed."); | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
Oops, something went wrong.