oversightstudio

encrypted fields

by oversightstudio
payload-plugins
Custom fields
v3
^3.90.0
MIT

Overview

Summary generated from the README

Provides an encryptedField function that wraps common Payload field types and encrypts their values before they are stored. It uses AES-256-CTR with the PAYLOAD_SECRET and a random IV, and hooks handle encryption and decryption automatically in the admin panel and the API. Encrypted fields cannot be sorted or filtered in the database.

Features

  • encryptedField function for use in collection field configs
  • AES-256-CTR encryption with a random IV and PAYLOAD_SECRET
  • Supports text, number, select, checkbox, email, date, json, textarea, code and radio fields
  • Works with hasMany on select and number fields
  • Automatic encryption and decryption through hooks in admin and API
  • Preserves original data types by JSON serialising before encryption

Use cases

  • Protect personal data such as names, birth dates or emails stored in collections
  • Store sensitive JSON or code snippets encrypted at rest in the database

From the author

Database field encryption for Payload.

Installation

npm i @oversightstudio/encrypted-fields

83

Stars

9

Forks

2

Open Issues

Today

Last Updated

55

Weekly Downloads

v1.0.0

npm Version

9.9 KB

Unpacked Size

0

Dependencies

Repository stars

Trends appear after 7 days of data. Daily snapshots have not started yet.

Shared by 3 plugins in oversightstudio/payload-plugins.

npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

Each point is npm's rolling 7-day download count.

Health Score

69/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/932147916-encrypted-fields.svg)](https://payloaddirectory.dev/plugins/932147916-encrypted-fields)
HTML
<a href="https://payloaddirectory.dev/plugins/932147916-encrypted-fields"><img src="https://payloaddirectory.dev/badge/932147916-encrypted-fields.svg" alt="Payload Directory"></a>
Updated Oct 20, 2026Created Feb 13, 2025Published Mar 2, 2025

README

Payload Encrypted Fields

Install

pnpm add @oversightstudio/encrypted-fields @payloadcms/ui

About

This package brings encrypted fields to Payload. It provides an encryptedField function that allows you to easily add encrypted fields to your collections.

It supports most field field types, including ones like select or number with hasMany enabled. Additionally, it fully integrates with Payload’s field customization options and lifecycle events, making it behave just like any other field—just encrypted.

The package automatically encrypts and decrypts field values using hooks, meaning you don’t need any extra setup to use encrypted fields in the admin panel or through the API.

Encryption

This package uses AES-256-CTR encryption, combined with your PAYLOAD_SECRET and a random IV. The encrypted value is stored as a string in the database.

For a deeper dive into how this encryption works, check out this blog post by Payload. It explains the same encryption approach but for a simple text field. This package expands on that to support more field types and make integration seamless.

Since encryption fundamentally converts data into an unreadable format, this package JSON stringifies your data before encrypting it and automatically parses it back after decryption to retain it's original data type.

Tradeofs

Using field encryption comes with some tradeoffs:

  • Larger data size – Encrypted values take up more space than raw values.
  • No sorting or filtering – Since the data is encrypted at rest, the database cannot sort or filter it.
  • Performance overhead – Encrypting and decrypting data adds some processing time.

These tradeoffs are standard when working with encrypted data, but they’re well worth it if protecting sensitive information is your goal.

Usage

Important: Make sure the PAYLOAD_SECRET environment variable is set before using this package.

import { CollectionConfig } from 'payload'
import { encryptedField } from '@oversightstudio/encrypted-fields'

export const SensitiveDataCollection: CollectionConfig = {
  slug: 'sensitive-data',
  fields: [
    encryptedField({
      name: 'name',
      type: 'text',
    }),
    encryptedField({
      name: 'age',
      type: 'number',
    }),
    encryptedField({
      name: 'birthDate',
      type: 'date',
    }),
    encryptedField({
      name: 'traits',
      type: 'select',
      options: [
        { label: 'Awesome', value: 'awesome' },
        { label: 'Based', value: 'based' },
        { label: 'Goat', value: 'goat' },
      ],
      hasMany: true,
    }),
  ],
}

Supported Field Types

Field TypeSupported
text✅ Yes
number✅ Yes
select✅ Yes
checkbox✅ Yes
email✅ Yes
date✅ Yes
json✅ Yes
textarea✅ Yes
code✅ Yes
radio✅ Yes
point❌ Not yet supported
richText❌ Not yet supported

All other missing field types (like as ui, tabs, etc.) are of course not supported, as they do not store user data that needs encryption.

Credits

  • Shoutout to Paul for being a real one.

Similar plugins