integraciones para cloud recovery Reviewed-on: #9 Co-authored-by: hreyes <hreyes@aduanasoft.com.mx> Co-committed-by: hreyes <hreyes@aduanasoft.com.mx>
27 lines
998 B
TypeScript
27 lines
998 B
TypeScript
/**
|
|
* Cifrado simétrico AES-256-GCM para secretos en reposo (estándar Aduanasoft §4).
|
|
* Se usa para `restore_targets.sql_password`: las credenciales SQL de los servidores
|
|
* de restauración nunca se guardan en texto plano en PostgreSQL.
|
|
*
|
|
* La lógica criptográfica vive en `crypto-core.ts` (pura y testeable). Aquí solo se
|
|
* resuelve la clave de 256 bits desde ENCRYPTION_KEY y se delega.
|
|
*/
|
|
import { env } from '$env/dynamic/private';
|
|
import { encryptWithKey, decryptWithKey, decodeKey, isEncrypted } from './crypto-core';
|
|
|
|
function getKey(): Buffer {
|
|
return decodeKey(env.ENCRYPTION_KEY);
|
|
}
|
|
|
|
/** Cifra un secreto en texto plano. Devuelve el sobre versionado listo para persistir. */
|
|
export function encryptSecret(plaintext: string): string {
|
|
return encryptWithKey(plaintext, getKey());
|
|
}
|
|
|
|
/** Descifra un sobre producido por `encryptSecret`. */
|
|
export function decryptSecret(payload: string): string {
|
|
return decryptWithKey(payload, getKey());
|
|
}
|
|
|
|
export { isEncrypted };
|