Skip to content

Cyber Security / Cryptography

Diffie–Hellman: Device Keys And Message Envelopes

Diffie–Hellman: Device Keys And Message Envelopes .--------. .--------. | A | | B | | o | | o | | /|\ | | /|\ | | / \ | | / \ | '---+----' '----+---' | | +-------- g^a ------------>| |<------------ g^b --------+ | | .--+--. .--+--. | g^ab| | g^ab| '-----' '-----'

How device-held private keys, shared secrets, and recipient envelopes work together—without sending the secret or encrypting the whole message for every recipient.

Two Layers Of Encryption

The supplied app description separates an older encryption path for leads and legacy messages from a newer device-key system. The newer path combines three jobs: agreeing on a secret, deriving a key for a specific purpose, and encrypting a message. These are separate steps, not competing ways of doing the same thing.

Generating Keys On The Device

Completing the drag-boxes-into-basket game opens the device-key setup. The browser generates a pair of keys: a private key that stays on the device and a public key that can be shared with other users.

In the described system, the private key is created as non-extractable. Browser cryptographic operations can use it, but ordinary application code cannot export its raw bytes. The app stores a browser-managed key object in local device storage rather than sending the private key to the server. The public key is published so other people can prepare messages for its owner.

The game is a user-experience gate, not a source of cryptographic entropy. Actual randomness comes from the browser’s cryptographically secure random-number generator. Moving boxes does not make the mathematical key stronger.

Agreeing On A Shared Secret

Diffie–Hellman key agreement lets two people independently arrive at the same secret without transmitting that secret. Alice combines her private key with Bob’s public key. Bob combines his private key with Alice’s public key. The two operations produce the same shared result.

An observer who sees only the public keys cannot feasibly recover that result under the key agreement’s security assumptions. Neither person needs to reveal a private key to the other person or to the server.

However, key agreement alone does not prove who owns a public key. The application must also authenticate the public-key association; otherwise, an attacker could substitute a key and establish separate secrets with each participant.

Deriving A Purpose-Specific Key

The raw shared result is not used directly to encrypt a message. A key-derivation step turns it into a key reserved for protecting message keys. A purpose label separates this use from other uses of the same underlying secret.

Derivation does not create new entropy or rescue a weak shared secret. It converts suitable secret material into the form and context the next operation needs. The result here is a key-encryption key: a key that protects another key.

Encrypting Once, Sharing With Many

For each message, the app generates a fresh random message key and a fresh nonce, then encrypts the message body once. Authenticated encryption also checks whether the encrypted body has been altered.

For every recipient, the app protects that same message key using the recipient-specific key derived from the shared secret, with a separate nonce. The stored result is one encrypted body plus a small envelope for each recipient. The envelope contains the protected message key, not another complete copy of the message.

To read the message, Bob uses his private key and Alice’s public key to reproduce their shared secret and derive the key-encryption key. He opens his envelope, recovers the message key, and decrypts the body. Other recipients follow the same sequence using their own envelopes. A versioned format lets the application distinguish future formats from earlier ones.

What These Boundaries Do—and Do Not—Protect

Keeping a private key non-extractable limits raw-key export; it is not a guarantee against a compromised device or malicious code running inside the app. Such code may still request operations with an accessible key or read plaintext when it is displayed. Device access, application integrity, public-key authentication, nonce handling, and key recovery remain important.

Fresh message keys and recipient envelopes also do not, by themselves, establish ratcheting, forward secrecy, or recovery after a key compromise. Those properties require additional key-lifecycle mechanisms and must not be inferred from this workflow alone.

This explanation adapts the owner-supplied implementation description. It describes that design without naming specific encryption protocols; it is not an independent audit or a claim that every portfolio project uses the same key-storage model.

Cryptography

Comments (3)

Demo discussion
  • Flavio Puente

    Flavio@tinyswan738

    Paint mixing gives a memorable picture of combining public information with a private contribution.

    • Earl Davis

      Earl@brownelephant995

      How would you explain where that analogy stops capturing the mathematical difficulty of recovering the secret?

    • Clara Mortensen

      Clara@beautifulgorilla430

      Authentication deserves a separate mention: agreeing on a shared key doesn't by itself establish who is on the other end.

      Elsewhere in the notebook