To take payments on your own site you paste some secret values into your admin. Anyone who gets hold of them may be able to act on your Stripe account, so how they are kept matters. Djangify now encrypts them. This article explains what that protects, what it does not, what to do if a key gets out and how to look after the rest.
- The Stripe secret key, webhook secret and email password are encrypted when saved.
- The admin does not show a saved secret back to you.
- Leaving a secret field empty keeps the value already saved.
- Self-hosted sites need an encryption key, and it must be kept safe.
- Encryption does not help if someone else can log in as you.
What each value does
| Value | What it is for | Secret? |
|---|---|---|
| Publishable key (pk_) | Lets your checkout talk to Stripe | No, it is meant to be public |
| Secret key (sk_) | Acts on your Stripe account | Yes |
| Webhook secret (whsec_) | Proves a payment message came from Stripe | Yes |
| Email password | Lets your site send mail | Yes |
The webhook secret is the one people understand least. After a payment, Stripe sends your site a message saying it happened. Your site uses this secret to check that the message really came from Stripe before it hands over a download. Without that check, anyone who knew where to send a message could pretend a payment had been made.
What changed
The saved value is scrambled. Reading it back needs a separate key that is not stored beside it.
The field shows dots, never your secret. Type in it only when you want to replace the value.
You can still leave these fields empty and keep the values in your environment settings file instead. You can also change one without retyping the others.
What encryption does not protect
Encryption helps if someone reads the saved data, for example from a copy of your database. It cannot help with these.
- A stolen admin password. Someone logged in as you can change your settings.
- A secret you shared. A screenshot, an email or a chat message keeps its own copy.
- A whole server in the wrong hands. The site needs the encryption key to work, so someone who controls the server can reach both.
- A convincing fake email. If you type your Stripe password into a copy of its sign in page, no setting on your site can stop that.
If you host your own site
Your site needs a value called ENCRYPTION_KEY in its environment settings. Without it, the encrypted fields cannot work.
If the encryption key is lost or changed, the saved secrets cannot be read. Keep a copy somewhere safe and private, apart from the server. Without it you would need to enter your secrets again.
Include it in your own notes for moving server. A site restored on a new machine with a different key will look complete and still fail at the payment step.
If a secret may have been seen
Act on a suspicion. Replacing a key costs a few minutes.
- Replace it at the sourceRoll the key in your Stripe dashboard, or change the password with your email provider.
- Save the new value on your sitePaste it into the matching field.
- Make a test purchaseCheck that payment, order and download all happen.
- Look at recent activityRead your Stripe account for anything you do not recognise, and contact Stripe if you find it.
Your part
Look after your keys
- Use a strong, unique admin password
- Turn on two step sign in for Stripe and your email
- Never paste a secret into a chat, email or screenshotThat includes a chat with an AI assistant.
- Practise with test keysThey start sk_test_ and move no real money.
- Remove access for helpers who have finished
- Your payment and email secrets are encrypted when saved in the admin.
- Keep your encryption key safe if you host the site.
- Protect your logins, and replace any key that may have been exposed.
If you are still choosing who runs the server, read Self-Hosted or Managed Hosting.