prorm API Reference
    Preparing search index...

    Class FieldEncryption

    Convenience class grouping the encryption API.

    Index
    configure: (key: string | Buffer<ArrayBufferLike>) => void = configureFieldEncryption

    Configure the global AES-256-GCM key.

    Type Declaration

      • (key: string | Buffer<ArrayBufferLike>): void
      • Configure the global encryption key. Call once at app startup before any encrypted models are used.

        Parameters

        • key: string | Buffer<ArrayBufferLike>

          A 32-byte key as a hex string (64 hex chars) or raw Buffer.

        Returns void

    encrypt: (plain: string) => string = encryptValue

    Manually encrypt a value.

    Type Declaration

      • (plain: string): string
      • Encrypt a plain-text value. Returns a prefixed base64 string: "enc:v1:::"

        Parameters

        • plain: string

        Returns string

    decrypt: (ciphertext: string) => string = decryptValue

    Manually decrypt a value.

    Type Declaration

      • (ciphertext: string): string
      • Decrypt a value produced by encryptValue(). Returns the original plain-text string.

        Parameters

        • ciphertext: string

        Returns string

    isEncrypted: (value: string) => boolean = isEncrypted

    Check if a value is already encrypted.

    Type Declaration

      • (value: string): boolean
      • Checks whether a value is already in encrypted form (prefixed with enc:v1:), used to avoid double-encrypting.

        Parameters

        • value: string

        Returns boolean

    applyHooks: (ModelClass: any) => void = applyEncryptionHooks

    Wire hooks onto a model.

    Type Declaration

      • (ModelClass: any): void
      • Wire beforeSave and afterFind hooks onto a model to transparently encrypt on write and decrypt on read.

        Call once per model after it is defined: applyEncryptionHooks(User);

        Parameters

        • ModelClass: any

        Returns void

    getFields: (target: Function) => string[] = getEncryptedFields

    Get the list of encrypted fields on a model.

    Type Declaration

      • (target: Function): string[]
      • Get the list of fields marked for encryption on a model class.

        Parameters

        • target: Function

        Returns string[]