EncryptedStorage

Secure implementation of Storage that provides transparent encryption of stored data. This implementation is suitable for sensitive information that needs to be protected at rest.

Security features:

  • Transparent encryption/decryption

  • No plaintext storage on disk

  • Support for various encryption algorithms

  • Secure error handling

Usage example:

val storage = EncryptedStorage(
fs = JVMFileSystemProvider,
encryption = Aes256GCMEncryption(secretKey)
)

// Store sensitive data
storage.write(secretPath, "sensitive information")

// Read encrypted data
val decrypted = storage.read(secretPath)

Parameters

Path

Platform-specific path type

fs

File system provider for I/O operations

encryption

Service for data encryption/decryption

Constructors

Link copied to clipboard
constructor(fs: FileSystemProvider.ReadWrite<Path>, encryption: Encryption)

Functions

Link copied to clipboard
open suspend override fun createDirectories(path: Path)

Creates directory hierarchy (unencrypted). Directory names and structure remain unencrypted as only file contents are protected. This is a design choice that balances security with usability.

Link copied to clipboard
open suspend override fun exists(path: Path): Boolean

Verifies path existence without accessing encrypted content. This operation is safe as it doesn't expose any protected data.

Link copied to clipboard
open suspend override fun read(path: Path): String?

Reads and decrypts file content securely. This operation ensures:

Link copied to clipboard
open suspend override fun write(path: Path, content: String)

Encrypts and writes content securely. This operation ensures: