Guides

VAPID keys explained

The two keys behind every web push subscription, what each one is for, and the one mistake that silently loses your subscribers.

Short answerVAPID (RFC 8292) is a pair of elliptic-curve keys (P-256). The public key goes to the browser when a visitor subscribes. The private key stays on your server and signs every push request. A subscription only accepts pushes signed by the key pair it was created with, so if you change keys, every existing subscriber stops receiving messages.

What VAPID is

VAPID stands for Voluntary Application Server Identification. It is defined in RFC 8292 and lets a website’s server prove to a browser’s push service that it is the same server the visitor subscribed to. Every browser that supports web push requires it today.

A VAPID key pair is an elliptic-curve key pair on the P-256 curve (also called prime256v1 or secp256r1):

  • The public key (65 bytes, usually 87 characters of URL-safe Base64) is given to the browser when a visitor subscribes, as the applicationServerKey. It isn’t secret.
  • The private key (32 bytes, 43 characters) stays on your server. It signs a short-lived token (a JWT) attached to every push request.

How the keys are used

  1. Your page calls pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: publicKey }).
  2. The browser’s push service creates a subscription and remembers which public key it belongs to.
  3. When you send, your server creates a JWT with the push service’s origin as audience, an expiry (at most 24 hours) and a contact (mailto: or a URL) as subject, and signs it with the private key.
  4. The push service checks the signature against the public key stored with the subscription. If they don’t match, it rejects the request (Chrome returns 403).

VAPID identifies the sender. It is separate from payload encryption, which uses the subscription’s own p256dh and auth keys.

Why changing keys loses subscribers

Each subscription is bound to the public key it was created with. If you generate a new pair, pushes signed with the new private key are rejected for every existing subscription. Visitors would have to subscribe again. In practice:

  • Generate one key pair per website and never regenerate it casually.
  • Back up the private key in your secrets manager.
  • When you change push provider, take your key pair with you. That is the only way to keep existing subscribers (how to migrate).

SuperWicket creates a separate key pair for each website and stores the private key encrypted. You can also import an existing pair when you add a website.

How to generate VAPID keys

In your browser: use our VAPID key generator. It uses the Web Crypto API on the page, so the private key never leaves your machine.

Node.js:

npx web-push generate-vapid-keys

PHP (minishlink/web-push):

use Minishlink\WebPush\VAPID;
print_r(VAPID::createVapidKeys()); // ['publicKey' => '...', 'privateKey' => '...']

Python (py-vapid):

pip install py-vapid
vapid --gen

OpenSSL:

openssl ecparam -name prime256v1 -genkey -noout -out vapid_private.pem
openssl ec -in vapid_private.pem -pubout -out vapid_public.pem

OpenSSL gives you PEM files. Most libraries expect the raw keys in URL-safe Base64, so convert them or use one of the tools above.

Key formats you’ll see

FormatPublic keyPrivate keyUsed by
URL-safe Base64 (raw)87 chars, starts with B43 charsweb-push, minishlink/web-push, pywebpush, most services
JWKx and ydWeb Crypto, some JOSE libraries
PEMSPKI blockEC or PKCS#8 blockOpenSSL, py-vapid files

The public key starts with B because the uncompressed point begins with the byte 0x04.

The “subject” field

Libraries ask for a subject alongside the keys, either mailto:[email protected] or your site’s URL. Push services use it to contact the sender if something goes wrong. Apple’s push service rejects a localhost URL as the subject (it returns BadJwtToken), so use a real address or public URL.

Frequently asked questions

Is the VAPID public key secret?

No. It is sent to every browser as the applicationServerKey when it subscribes. Only the private key must be kept secret.

Can I use the same VAPID keys for several websites?

Technically yes, but separate pairs per website are safer: one leaked key then affects one site, and you can move a single site to another provider without touching the others. SuperWicket creates a separate pair for each website.

What happens if I lose my VAPID private key?

You can’t send to the existing subscriptions any more. Visitors have to subscribe again with a new key pair. Back up the private key somewhere safe.

What format are VAPID keys in?

Usually URL-safe Base64 without padding. The public key is the 65-byte uncompressed P-256 point (87 characters). The private key is the 32-byte scalar (43 characters).

Try it on your own site

The Free plan has no time limit and needs no card. Add one script tag, or share a hosted subscribe page if you can’t upload files.