ProtectedconstructorGets only active encryption algorithms.
Gets only active encryption keys.
Gets only active encryption key sources.
ProtectedBaseAccess the contained EncryptionEngineBase instance for metadata operations.
Gets all cached encryption algorithms.
Gets all cached encryption keys.
Gets all cached encryption key sources.
Whether the base engine has been loaded/configured.
StaticInstanceGets the singleton instance of the encryption engine.
The instance is created on first access and reused thereafter.
Clears all caches including base class metadata caches.
This is more aggressive than ClearCaches() and should be used when you need to completely refresh all cached data.
Clears key material and source caches.
Call after key rotation or configuration changes to ensure fresh data is loaded. The base class metadata caches are handled separately via RefreshAllItems().
Key material buffers are explicitly zeroed before removal to minimize the window where sensitive bytes linger in memory.
Configures the engine by loading encryption metadata from the database.
Delegates to EncryptionEngineBase to load metadata. Must be called before performing encryption/decryption operations.
OptionalforceRefresh: booleanIf true, reloads data even if already loaded
OptionalcontextUser: UserInfoUser context for database access (required server-side)
Optionalprovider: IMetadataProviderOptional metadata provider override
Decrypts an encrypted value.
If the value is not encrypted (doesn't start with marker), returns it unchanged.
The method:
The value to decrypt (may or may not be encrypted)
OptionalcontextUser: UserInfoUser context for database access
The decrypted plaintext, or original value if not encrypted
Encrypts a value using the specified encryption key.
The method:
The result format is:
$ENC$<keyId>$<algorithm>$<iv>$<ciphertext>[$<authTag>]
This format contains all information needed for decryption.
The value to encrypt (string or Buffer)
UUID of the encryption key to use
OptionalcontextUser: UserInfoUser context for database access
The encrypted value as a string
Encrypts a value using a specific key lookup (for key rotation).
During key rotation, we need to encrypt with the new key material before updating the key metadata. This method allows specifying an alternate lookup value for the key material.
The value to encrypt
The key ID (for algorithm/marker config)
Alternate lookup value for key material
OptionalcontextUser: UserInfoUser context for database access
The encrypted value string
Gets an encryption algorithm by its ID.
The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.
Gets an encryption key by its name (case-insensitive).
Gets the full configuration for an encryption key, including its algorithm and source.
Gets the marker prefix for a specific encryption key.
Gets an encryption key source by its driver class name.
Gets an encryption key source by its ID.
Checks if a value is encrypted.
Encrypted values start with the marker prefix (default: '$ENC$'). This also checks for the encrypted sentinel value. This is a fast, synchronous check that doesn't require database access.
The value to check
OptionalencryptionMarker: stringOptional custom marker to check for (defaults to '$ENC$')
true if the value appears to be encrypted or is the sentinel value
Parses an encrypted value string into its component parts.
Use this when you need to inspect the encrypted value without decrypting.
The encrypted value string
Parsed components (marker, keyId, algorithm, iv, ciphertext, authTag)
Refreshes all cached items in the base engine.
Validates that ALL active encryption keys have accessible key material.
This method iterates through every active encryption key in the system,
instantiates the appropriate key source provider, and delegates validation
to each provider's ValidateKeyAccessibility() method. Each provider
encapsulates its own validation logic and generates source-specific
error messages with actionable remediation steps.
The engine never touches key material during validation — that stays encapsulated within each provider.
OptionalcontextUser: UserInfoUser context for database access
Array of validation results, one per active key
Validates that a key is usable for encryption operations.
Validates that key material is accessible at a given lookup value.
Used before key rotation to verify the new key exists and is valid.
The key source lookup value to validate
The key ID (to get source configuration)
OptionalcontextUser: UserInfoUser context for database access
Protected StaticgetReturns the singleton instance of the class. If the instance does not exist, it is created and stored in the Global Object Store. If className is provided it will be used as part of the key in the Global Object Store, otherwise the actual class name will be used. NOTE: the class name used by default is the lowest level of the object hierarchy, so if you have a class that extends another class, the lowest level class name will be used.
OptionalclassName: string
Core encryption engine for field-level encryption operations.
This class uses composition to delegate metadata operations to EncryptionEngineBase while adding encryption/decryption capabilities. This avoids duplicate entity registration that occurred when using inheritance.
Use
EncryptionEngine.Instanceto access the singleton.Thread Safety
The engine is designed to be safe for concurrent use in async contexts. Cache operations are atomic Map operations and crypto operations use per-call state.
Error Handling
The engine throws descriptive errors for:
Callers should catch and handle errors appropriately.