| Crates.io | df-share |
| lib.rs | df-share |
| version | 0.1.1 |
| created_at | 2025-01-20 14:03:09.082866+00 |
| updated_at | 2025-01-26 17:34:58.44477+00 |
| description | secret sharing |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1523911 |
| size | 34,229 |
df-share is a lightweight helper library for one-off (ephemeral) Diffie-Hellman exchanges that let a server encrypt a secret so only the requesting client can decrypt it. The server uses a freshly generated key pair for each request, returning (encrypted_secret, server_pubk, nonce, salt). The client then uses the corresponding ephemeral keys on its side to derive the shared secret and decrypt.
// Client side
let client = EphemeralClient::new().unwrap();
let (req, decryptor) = client.sendable();
// The client sends `req` (which includes its ephemeral public key)
// to the server. Then the server encrypts the secret:
let res;
let secret = "MyVerySecretPrivateKey";
{
// Server side
let server = EphemeralServer::new().unwrap();
res = server.encrypt_secret(&req, secret.as_bytes()).unwrap();
}
// Back on the client side, we decrypt using the matching ephemeral keys:
let decrypted_secret = decryptor.decrypt(&res).unwrap();
assert_eq!(secret.as_bytes(), &decrypted_secret);
// Confirm the ciphertext differs from the secret:
assert!(decrypted_secret != res.ciphertext);
In this snippet:
req message.req, and encrypts the actual secret.Use df-share to keep your secret data private between two parties, as long as you’re operating over a trusted channel (e.g., HTTPS) or have other means to ensure the server is who you expect.