AbstractCreates a new key source instance.
Note: The config may be empty/undefined when using ClassFactory. Configuration is typically loaded from the database and passed when retrieving keys.
Optionalconfig: EncryptionKeySourceConfigOptional configuration for the key source
Protected_Configuration passed during instantiation. Contains lookupValue and any source-specific additional config.
Optional cleanup for sources with connections or resources.
Called during graceful shutdown to release resources. Use this for:
The default implementation is a no-op for stateless sources.
Override in subclasses that hold resources
AbstractGetRetrieves the raw key material for the given lookup value.
Keys should be base64-encoded in the source storage. The provider decodes and returns raw bytes.
Identifier for the key in this source
OptionalkeyVersion: stringOptional version for versioned key stores. Some sources (like vaults) maintain multiple versions. If not specified, returns the current/latest version.
Promise resolving to raw key bytes as a Buffer. The buffer length must match the algorithm's KeyLengthBits/8.
Optional async initialization for sources that need setup.
Called once by the encryption engine before first use. Use this for:
The default implementation is a no-op for simple sources.
Override in subclasses that need async initialization
AbstractKeyChecks if a key exists without retrieving it.
Used for validation before operations that would fail on missing keys. More efficient than GetKey() when you only need existence check.
Identifier for the key in this source
Promise resolving to true if key exists, false otherwise
AbstractValidateValidates that the source is properly configured.
Called before attempting key operations to fail fast on misconfiguration. Check for:
true if configuration is valid, false otherwise
AbstractValidateValidates that a specific key is accessible and usable from this source.
Each provider implements source-specific validation logic and returns actionable remediation messages on failure. This keeps key-source-specific knowledge encapsulated within the provider rather than in the engine.
{ IsAccessible: true } only if key material can be retrieved
and passes all validation (exists, valid format, correct length if expectedKeyLengthBytes provided)Error string with remediation steps on failureIdentifier for the key in this source
OptionalkeyVersion: stringOptional version for versioned key stores
OptionalexpectedKeyLengthBytes: numberOptional expected key length in bytes for validation. When provided, the provider should retrieve the key and verify its length matches.
Promise resolving to a validation result
Abstract base class for encryption key source providers.
Key sources are responsible for securely retrieving encryption key material from various backends. The MemberJunction encryption system uses the ClassFactory pattern to instantiate the appropriate provider based on database configuration.
Security Considerations
Never log or expose key material - Key bytes should only be returned via the GetKey() method and immediately used for crypto operations.
Validate inputs - Always validate lookupValue parameters to prevent injection attacks against your backend.
Use secure connections - For network-based sources (vaults, KMS), always use TLS and verify certificates.
Handle errors securely - Don't expose internal details in error messages that could help attackers.
Lifecycle