Web Crypto: deriveBits
This page shows how to use the
deriveBits() function of the Web Crypto API. It contains two separate examples, one for PBKDF2 and one for ECDH.
It's important to note that although both are defined in the API as key derivation functions, PBKDF2 and ECDH have very different use cases and characteristics.
The PBKDF2 algorithm is used here to derive some bits from a password.
When you click "Derive bits" the example prompts you for a password and then derives some bits from the password using PBKDF2, and a representation of the derived bits is displayed.
The ECDH algorithm is more commonly called a "key agreement" algorithm. It enables two parties (conventionally called "Alice" and "Bob"), each of whom has a public/private key pair, to establish a shared secret key.
With this example we've created two ECDH key pairs, one for Alice and one for Bob.
When you click "Derive bits" the example uses Alice's private key and Bob's public key to derive a shared secret, and a representation of the shared secret is displayed.