Skip to content

Instantly share code, notes, and snippets.

@pinkeshdarji
Created June 25, 2021 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinkeshdarji/83f1d0281eb9f3be500649a37370ae35 to your computer and use it in GitHub Desktop.
Save pinkeshdarji/83f1d0281eb9f3be500649a37370ae35 to your computer and use it in GitHub Desktop.
Future<void> _deriveKey() async {
//1. Alice's public key
Map<String, dynamic> publicjwk = json.decode(
'{"kty": "EC", "crv": "P-256", "x": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "y": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}');
EcdhPublicKey ecdhPublicKey =
await EcdhPublicKey.
(publicjwk, EllipticCurve.p256);
//2. Bob's private key
Map<String, dynamic> privatejwk = json.decode(
'{"kty": "EC", "crv": "P-256", "x": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "y": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "d": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}');
EcdhPrivateKey ecdhPrivateKey =
await EcdhPrivateKey.
(privatejwk, EllipticCurve.p256);
//3. Generating cryptokey called deriveBits
Uint8List derivedBits = await ecdhPrivateKey.deriveBits(256, ecdhPublicKey);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment