e2ee-adapter
Version:
Plug-and-play End-to-End Encryption middleware for Express.js and NestJS using hybrid AES-CBC + RSA encryption with secure key exchange
72 lines • 2.56 kB
TypeScript
export interface KeyPair {
publicKey: string;
privateKey: string;
}
export interface DecryptionResult {
decryptedData: string;
aesKey?: Buffer;
iv?: Buffer;
}
/**
* Generate RSA key pair
* @param keySize - Key size in bits (default: 2048)
* @returns Promise<KeyPair>
*/
export declare function generateKeyPair(keySize?: number): Promise<KeyPair>;
/**
* Encrypt data using hybrid encryption (AES-CBC + RSA)
* @param data - Data to encrypt
* @param publicKey - RSA public key
* @returns Promise<{ encryptedData: string, aesKey: Buffer, iv: Buffer, originalAesKey: Buffer }>
*/
export declare function encrypt(data: string, publicKey: string): Promise<{
encryptedData: string;
aesKey: Buffer;
iv: Buffer;
originalAesKey: Buffer;
}>;
/**
* Decrypt only the AES key from the encrypted key header (for empty request bodies)
* @param encryptedKey - Encrypted AES key (base64)
* @param privateKey - RSA private key
* @returns Promise<{ aesKey: Buffer, iv: Buffer }>
*/
export declare function decryptAESKey(encryptedKey: string, iv: string, privateKey: string): Promise<{
aesKey: Buffer;
iv: Buffer;
}>;
/**
* Decrypt data using hybrid decryption (AES-CBC + RSA)
* @param encryptedData - Encrypted data (base64)
* @param encryptedKey - RSA encrypted AES key (base64)
* @param iv - Initialization vector (base64)
* @param privateKey - RSA private key
* @returns Promise<DecryptionResult>
*/
export declare function decrypt(encryptedData: string, encryptedKey: string, iv: string, privateKey: string): Promise<DecryptionResult>;
/**
* Encrypt data using AES-CBC (for server responses)
* @param data - Data to encrypt
* @param aesKey - AES key
* @param iv - Initialization vector
* @returns string - Encrypted data (base64)
*/
export declare function encryptAES(data: string, aesKey: Buffer, iv: Buffer): string;
/**
* Decrypt data using AES-CBC (for client responses)
* @param encryptedData - Encrypted data (base64)
* @param aesKey - AES key
* @param iv - Initialization vector
* @returns string - Decrypted data
*/
export declare function decryptAES(encryptedData: string, aesKey: Buffer, iv: Buffer): string;
/**
* Generate multiple RSA key pairs for multi-domain support
* @param keyIds - Array of key IDs to generate
* @param keySize - Key size in bits (default: 2048)
* @returns Promise<{ [keyId: string]: KeyPair }>
*/
export declare function generateMultipleKeyPairs(keyIds: string[], keySize?: number): Promise<{
[keyId: string]: KeyPair;
}>;
//# sourceMappingURL=crypto.d.ts.map