• Checks if a string value is encrypted or is the encrypted sentinel.

    This function returns true if the value:

    • Equals the encrypted sentinel ([!ENCRYPTED$]), indicating a protected value not disclosed to the client
    • Starts with the encryption marker (default $ENC$ or a custom marker if provided)

    Parameters

    • value: string

      The value to check

    • Optional encryptionMarker: string

      Optional custom encryption marker prefix. If not provided, uses the default $ENC$. This allows for per-key markers as defined in the EncryptionKey entity's Marker field.

    Returns boolean

    True if the value is the encrypted sentinel or starts with the encryption marker, false otherwise

    Example

    import { IsValueEncrypted, ENCRYPTION_MARKER } from '@memberjunction/global';

    const encrypted = '$ENC$keyId$AES-256-GCM$iv$ciphertext$authTag';
    const customEncrypted = '$CUSTOM$keyId$AES-256-GCM$iv$ciphertext';
    const sentinel = '[!ENCRYPTED$]';
    const plaintext = 'Hello World';

    console.log(IsValueEncrypted(encrypted)); // true
    console.log(IsValueEncrypted(sentinel)); // true
    console.log(IsValueEncrypted(customEncrypted, '$CUSTOM$')); // true
    console.log(IsValueEncrypted(plaintext)); // false
    console.log(IsValueEncrypted(null)); // false
    console.log(IsValueEncrypted('')); // false