Keys
Signing and encryption solve different problems. A signature lets the recipient check who produced a message and whether it changed. Encryption limits who can read its contents. The SDK PKI libraries provide both, using separate key pairs so an application can publish the keys needed by its peers while retaining its private keys. The Account API describes the public JWKs mesgd accepts.
Key pairs
| Use | Algorithm | Public fields you publish |
|---|---|---|
| Signing | ECDSA P-256 | kty=EC, crv=P-256, use=sig, x, y |
| Encryption | RSA-2048 in the samples. mesgd accepts 2048 to 8192 | kty=RSA, use=enc, n, e |
Coordinates and integers are base64url. Private fields stay in the client key file.
Message formats
Message signatures in mesgd-sdk are JSON:
{"r":"<base64url>","s":"<base64url>"}
Encryption is RSA-OAEP with SHA-256 and MGF1-SHA-256. Erlang and the Python client interoperate on that encryption.
With RSA-2048 and SHA-256, a single OAEP operation can encrypt at most 190 bytes. A serialized public key set exceeds that limit. Implementations with hybrid registration support use RSA-OAEP to protect an AES key and A256GCM to encrypt the larger payload. Python and JavaScript registration still require a payload small enough for a single OAEP operation.
These registration helpers construct encrypted messages; the current server does not store them through /mesgd/pki. Publish an account's public keys with PUT /auth/keys, or include public_keys at signup.
mesgd forge returns a server token, ciphertext.signature. That is not this signature encoding. Do not verify a forged claim token with an SDK verify that expects {"r","s"}.
Cryptographic operations
| Operation | What your program uses it for |
|---|---|
sign | Sign with the signing private key |
verify | Check a signature |
encrypt | Encrypt to a public encryption key |
decrypt | Decrypt with the encryption private key |
import / export | Read and write the key file |
public / private | Export the half you mean to share, or the half you keep |
Names differ by language. The cross-language tests call these helpers:
| Language | Public JWK | Encrypt to a key | Verify with a public key |
|---|---|---|---|
| Python | pub_jwk | encrypt_with | verify_with_pub |
| JavaScript | pubJwk | encryptWith | verifyWithPub |
| Go | PubJWK | EncryptWith | VerifyWithPub |
| Rust | on the crate mesgd-pki | encrypt_with | verify_with_pub |
| Ruby | the names in ruby/pki.rb | encrypt_with | verify_with_pub |
| C | pki_pub_jwk | pki_encrypt_with | pki_verify_with_pub |
C helpers take JSON strings. Go's EncryptWith and VerifyWithPub are package functions, and PubJWK is a method. The Rust library is rust/pki.rs.
Erlang also has seal and open for a JWK that does not fit in one OAEP block.
Languages that still need a protocol helper, or a PKI rewrite, are listed in Languages. The samples show the call sequence that ships. See Samples.