Gmail
Gmail
Encrypted email with S/MIME key pairs protected by the DuoKey KACLS
How Gmail CSE works
Gmail CSE is built on S/MIME. Each user who sends or reads encrypted email needs an S/MIME certificate and its RSA private key. With CSE, Google never stores the private key in clear: you upload it wrapped by the DuoKey KACLS. When the user signs or decrypts a message in the browser, Gmail asks DuoKey to perform the private key operation:
| Operation | When | Who may call it |
|---|---|---|
wrapprivatekey | Once per key pair, before the upload to Gmail | Privileged users of the app |
privatekeysign | Sending a signed or encrypted email | The key pair owner, with a Google authorization token |
privatekeydecrypt | Reading an encrypted email | The key pair owner, with a Google authorization token |
privilegedprivatekeydecrypt | Privileged export (Takeout) | Privileged users of the app |
Prerequisites
Prerequisites
- Steps 1 to 5 of Getting Started done: DuoKey key service added and assigned to the users' OU
- Gmail selected in the app's Google applications
- Your administrator account listed as a privileged user of the DuoKey app
- An S/MIME certificate (RSA) and its private key for each user, issued by a CA that Gmail trusts or whose root you upload in the Admin console
- A Google Cloud service account with domain-wide delegation for the scope https://www.googleapis.com/auth/gmail.settings.basic
Step 1: Enable S/MIME and trust your CA
Turn on S/MIME for the OU
In the Google Admin console, open Apps, Google Workspace, Gmail, User settings, select the OU and open S/MIME. Turn on Enable S/MIME encryption for sending and receiving emails.
Upload the root certificate
If the user certificates come from your own CA, add its root under Accept these additional root certificates for specific domains, for your domain. Save.

Step 2: Turn on Gmail CSE
In Data, Compliance, Client-side encryption, open Gmail and turn on client-side encryption for the OU.
Step 3: Wrap each private key with DuoKey
Wrap the private key
On the app's detail page, in the Gmail S/MIME private key card, paste the user's RSA private key (PEM, PKCS#8 or PKCS#1, or base64 DER) and click Wrap private key.
Keep the result
DuoKey returns:
spki_hash: the SHA-256 hash of the public key, which DuoKey checks on every signature.wrapped_private_key: the private key wrapped by the vault key. Click Download to save it.

Once the key pair is uploaded to Gmail, the clear private key is no longer needed: Gmail uses only the wrapped key, and only through DuoKey. Delete every clear copy, or keep it in a protected escrow if your policy requires one.
Step 4: Upload the key pair through the Gmail API
Use the service account with domain-wide delegation, impersonating each user (sub = the user's email address) with the scope https://www.googleapis.com/auth/gmail.settings.basic.
Create the key pair
Call POST https://gmail.googleapis.com/gmail/v1/users/me/settings/cse/keypairs with:
{
"pkcs7": "<user certificate and chain, PKCS#7 PEM>",
"privateKeyMetadata": [{
"kaclsKeyMetadata": {
"kaclsUri": "<KACLS URL of the DuoKey app>",
"kaclsData": "<wrapped_private_key from DuoKey>"
}
}]
}The response contains a keyPairId.
Create the CSE identity
Call POST https://gmail.googleapis.com/gmail/v1/users/me/settings/cse/identities with:
{
"emailAddress": "<user email address>",
"primaryKeyPairId": "<keyPairId>"
}After the upload, the encryption option in the Gmail compose window can take up to 24 hours to appear for the user.
Step 5: Send an encrypted email
In Gmail, compose a new message, click the lock icon and turn on Additional encryption. Gmail encrypts the message in the browser and calls DuoKey to sign it. The recipient's browser calls DuoKey (or the recipient's own key service) to decrypt it. Each operation appears in the app's Key access log.
Encrypted email is sent with S/MIME: Gmail needs the recipient's certificate. Inside your organization the certificates come from the uploaded key pairs. For external recipients, exchange signed emails first so that each side has the other's certificate.