Overview:
Strapi’s Encryptable Field Plugin is a plugin that allows users to encrypt and decrypt data in Strapi. It is important to note that this plugin should not be used to store user passwords, as hashing should be used for that purpose. The plugin supports the aes-256-cbc encryption method and is only compatible with Strapi version 4.
Features:
- Encrypts data on create and update
- Decrypts data on fetch one and many
- Role-based decryption for selected roles
- Basic settings for validation regex and input hint
- Advanced settings for selectively showing decrypted values for roles
Installation:
- Open or create the file
config/plugins.js - Enable the plugin by adding the following snippet:
module.exports = ({ env }) => ({
// ...
settings: {
encryption: {
enabled: true,
encryptionKey: env('ENCRYPTION_KEY'),
},
},
});
- Add the environment variable
ENCRYPTION_KEYto your server and.envfile - Generate a key by running the following command in your terminal:
$ node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
- After installation and configuration, the custom field is ready to use. Add a new field and select “Encryptable” under the “Custom” tab.
Summary:
Strapi’s Encryptable Field Plugin is a useful plugin for encrypting and decrypting data in Strapi. It provides features such as role-based decryption, basic and advanced settings for customization, and easy installation and configuration. It is important to follow best practices and consult the rules around PII data when using this plugin in production.