-
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.
Merge pull request #366 from dajiaji/add-node-samples
Add samples for node.
- Loading branch information
Showing
19 changed files
with
607 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CipherSuite, DhkemP256HkdfSha256, HkdfSha256 } from "@hpke/core"; | ||
import { Chacha20Poly1305 } from "@hpke/chacha20poly1305"; | ||
|
||
async function doHpke() { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemP256HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Chacha20Poly1305(), | ||
}); | ||
|
||
const rkp = await suite.kem.generateKeyPair(); | ||
|
||
// A sender encrypts a message. | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
|
||
// A recipient decrypts it. | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, | ||
enc: sender.enc, | ||
}); | ||
const pt = await recipient.open(ct); | ||
|
||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
|
||
try { | ||
doHpke(); | ||
} catch (e) { | ||
console.log("Error:", e.message); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "node-hpke-core", | ||
"version": "1.0.0", | ||
"description": "A sample code of @hpke/core.", | ||
"type": "module", | ||
"main": "app.js", | ||
"author": "Ajitomi Daisuke <ajitomi@gmail.com> (https://github.com/dajiaji)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@hpke/chacha20poly1305": "^1.3.0", | ||
"@hpke/core": "^1.3.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Aes128Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256 } from "@hpke/core"; | ||
|
||
async function doHpke() { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemP256HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Aes128Gcm(), | ||
}); | ||
|
||
const rkp = await suite.kem.generateKeyPair(); | ||
|
||
// A sender encrypts a message. | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
|
||
// A recipient decrypts it. | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, | ||
enc: sender.enc, | ||
}); | ||
const pt = await recipient.open(ct); | ||
|
||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
|
||
try { | ||
doHpke(); | ||
} catch (e) { | ||
console.log("Error:", e.message); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "node-hpke-core", | ||
"version": "1.0.0", | ||
"description": "A sample code of @hpke/core.", | ||
"type": "module", | ||
"main": "app.js", | ||
"author": "Ajitomi Daisuke <ajitomi@gmail.com> (https://github.com/dajiaji)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@hpke/core": "^1.3.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core"; | ||
import { DhkemSecp256k1HkdfSha256 } from "@hpke/dhkem-secp256k1"; | ||
|
||
async function doHpke() { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemSecp256k1HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Aes128Gcm(), | ||
}); | ||
|
||
const rkp = await suite.kem.generateKeyPair(); | ||
|
||
// A sender encrypts a message. | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
|
||
// A recipient decrypts it. | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, | ||
enc: sender.enc, | ||
}); | ||
const pt = await recipient.open(ct); | ||
|
||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
|
||
try { | ||
doHpke(); | ||
} catch (e) { | ||
console.log("Error:", e.message); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "node-hpke-core", | ||
"version": "1.0.0", | ||
"description": "A sample code of @hpke/core.", | ||
"type": "module", | ||
"main": "app.js", | ||
"author": "Ajitomi Daisuke <ajitomi@gmail.com> (https://github.com/dajiaji)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@hpke/core": "^1.3.0", | ||
"@hpke/dhkem-secp256k1": "^1.3.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core"; | ||
import { DhkemX25519HkdfSha256 } from "@hpke/dhkem-x25519"; | ||
|
||
async function doHpke() { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemX25519HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Aes128Gcm(), | ||
}); | ||
|
||
const rkp = await suite.kem.generateKeyPair(); | ||
|
||
// A sender encrypts a message. | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
|
||
// A recipient decrypts it. | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, | ||
enc: sender.enc, | ||
}); | ||
const pt = await recipient.open(ct); | ||
|
||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
|
||
try { | ||
doHpke(); | ||
} catch (e) { | ||
console.log("Error:", e.message); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "node-hpke-core", | ||
"version": "1.0.0", | ||
"description": "A sample code of @hpke/core.", | ||
"type": "module", | ||
"main": "app.js", | ||
"author": "Ajitomi Daisuke <ajitomi@gmail.com> (https://github.com/dajiaji)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@hpke/core": "^1.3.0", | ||
"@hpke/dhkem-x25519": "^1.3.0" | ||
} | ||
} |
Oops, something went wrong.