UNPKG

dotencr

Version:

Encrypt and decrypt individual lines inside a .env file. Supports multiple encryption keys. Keys and dotenv files can be read text file or read from the environment.

89 lines (88 loc) 3.26 kB
import { DotenvVariable } from "./dotenv_variable"; import { CryptoKeyManager } from "./crypto_key_manager"; import { JWK } from "jose"; /** * Status of an attempt to encrypt or decrypt a dotenv variable */ export declare enum StatusCryptoWrapperResult { /** * Operation successful */ success = "success", /** * Encryption key could not be found */ missingEncryptionKey = "missingEncryptionKey", /** * An exception occurred during the encryption or decryption */ exception = "exception", /** * All the encryption keys were tried but none were successful. */ wildcardNoKeysMatch = "wildcardNoKeysMatch" } /** * Convert an error to something human readable */ export declare const statusCryptoWrapperToText: (status: StatusCryptoWrapperResult, keyName: string, exception?: Error | undefined) => string; /** * Status of an attempt to encrypt or decrypt a dotenv variable */ export interface CryptoWrapperResult { status: StatusCryptoWrapperResult; /** * If the encryption or decryption was successful, then the result is stored in this property. */ result?: string; /** * List of failure reasons */ failureExplanation: string[]; /** * If encrypting: This contains the name of the unencrypted variable * If decrypting: This contains the name of the ciphered variable */ oldDotenvVariableName: string; /** * If encrypting: This contains the name of the ciphered variable * If decrypting: This contains the name of the unencrypted variable */ newDotenvVariableName: string; } /** * Interface for encryption decryption */ export interface CryptoWrapperInterface { /** * Encryption decryption algorithm name */ algo(): string; /** * @see CryptoWrapperResult.newDotenvVariableName */ newDotEnvVariableName(dv: DotenvVariable): string; encryptWithKeyManager(plainText: DotenvVariable[]): CryptoWrapperResult[]; decryptWithKeyManager(cipherText: DotenvVariable[]): CryptoWrapperResult[]; encrypt(plainText: DotenvVariable, key: JWK.Key): CryptoWrapperResult; decrypt(cipherText: DotenvVariable, key: JWK.Key): CryptoWrapperResult; } export declare class CryptoWrapperAes256Gcm implements CryptoWrapperInterface { static readonly SYM_ENC_ALGO = "aes-256-gcm"; static readonly SYM_ENC_KEY_LENGTH = 32; static readonly SYM_ENC_IV_LENGTH = 12; static readonly SYM_ENC_TAG_LENGTH = 16; /** * Used exclusively for testing to force the IV to be the same value, so encrypted * always match the expected value. If TRUE, this weakens the strength of the encryption. */ private forceIvToFixedValue; cryptoMgr: CryptoKeyManager; constructor(cryptoMgr: CryptoKeyManager, forceIvToFixedValue?: boolean); algo(): string; newDotEnvVariableName(dv: DotenvVariable): string; encryptWithKeyManager(dotenvPlainTextVariables: DotenvVariable[]): CryptoWrapperResult[]; decryptWithKeyManager(dotenvCipherVariables: DotenvVariable[]): CryptoWrapperResult[]; encrypt(plainText: DotenvVariable, key: JWK.Key): CryptoWrapperResult; decrypt(cipherText: DotenvVariable, key: JWK.Key): CryptoWrapperResult; }