Crate rust_config_secrets

Crate rust_config_secrets 

Source
Expand description

§rust-config-secrets

rust-config-secrets is a library designed to safely manage secrets within configuration files. It allows you to encrypt sensitive data (like passwords, API keys) directly within your config strings or files, and decrypt them at runtime.

§Features

  • Encryption: Encrypt plain text configuration strings or files.
  • Decryption: Decrypt configuration strings or files containing SECRET(...) blocks.
  • Key Generation: Generate secure random keys for AES-256-GCM encryption.
  • Format Agnostic: Works with JSON, YAML, TOML, INI, or any text-based format.

§Usage

use rust_config_secrets::{encrypt_secrets, decrypt_secrets, generate_key};

let key = generate_key();
let config = r#"{ "password": "ENCRYPT(my_secret_password)" }"#;

// Encrypt the configuration
let encrypted_config = encrypt_secrets(config, &key).unwrap();
assert!(encrypted_config.contains("SECRET("));

// Decrypt the configuration
let decrypted_config = decrypt_secrets(&encrypted_config, &key).unwrap();
assert!(decrypted_config.contains(r#""password": "my_secret_password""#));

Enums§

ConfigSecretsError
Errors that can occur during configuration secret management.

Functions§

decrypt_file
Decrypts a configuration file and returns the content as a string.
decrypt_secrets
Decrypts all SECRET(...) blocks in the provided string.
decrypt_value
Decrypts a single value. Accepts either SECRET(...) format or raw encoded string.
encrypt_file
Reads a file, encrypts its secrets, and writes the result to a different output file.
encrypt_file_in_place
Reads a file, encrypts its secrets, and overwrites the file with the result.
encrypt_secrets
Encrypts all ENCRYPT(...) blocks in the provided string, converting them to SECRET(...).
encrypt_secrets_to_file
Encrypts secrets in a string and writes the result to a file.
encrypt_value
Encrypts a single value and returns the encoded ciphertext.
generate_key
Generates a random 32-byte AES key and returns it as an alphanumeric encoded string.