Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prisma-encrypter

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prisma-encrypter

Lightweight encryption solution for Prisma

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

Prisma Encryption

This package allows you to encrypt your models in Prisma

Installation

Install the package using npm

  npm install prisma-encrypter

Usage/Examples

If you use ivField on a model, don't forget to include this field in your select/update queries. key argument must be a 32-bits key iv argument must be a 16-bits key

This supports include models, included fields has to include the name of the field, for example accounts -> Account. TODO: analyze prisma.schema to make a correspondance table.

model Item {
  id              Int             @default(autoincrement()) @id
  accountId       Int?
  accounts        Account?        @relation(fields: [accountId], references: [id])
}

Basic usage

import { PrismaClient } from '@prisma/client';
import { encryptionMiddleware } from 'prisma-encrypter';

const prisma = new PrismaClient();

prisma.$use(
  encryptionMiddleware({
    global: {
      key: 'Xp2r5u8x/A?DcG+KbPeShVmYq3t6v9y$',
    },
    models: [
      {
        model: 'User',
        fields: ['password'],
      },
    ],
  })
);

Advanced usage

import { PrismaClient } from '@prisma/client';
import { encryptionMiddleware, encryptModels } from 'prisma-encrypter';

const prisma = new PrismaClient();
prisma.$use(
  encryptionMiddleware({
    global: {
      iv: 'C*F-J@NcRfUjXn2r',
      algorithm: 'aes-256-cbc',
    },
    models: [
      {
        model: 'User',
        fields: ['password', 'secret'],
        local: {
          key: '2p2r5u8x/A?DcG+KbPeShVmYq3t6v9y1',
          ivField: 'hash',
          stripIvField: true,
        },
      },
    ],
  })
);

// In another file, you can add more models (or one using encryptModel).
encryptModels([
  {
    model: 'Vault',
    local: {
      key: 'NcRfUjXn2r5u8x!A%D*G-KaPdSgVkYp3',
      iv: 'Zq4t7w!z%C*F-J@N',
      algorithm: 'aes-256-gcm',
    },
  },
  {
    model: 'Entries',
    fields: ['code'],
    local: {
      key: 'w9z$C&F)J@NcRfUjXn2r5u7x!A%D*G-K',
    },
  },
]);

//

The lib also exposes manualEncrypt() and manualDecrypt()

Keywords

FAQs

Package last updated on 03 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc