### Go Project Build Instructions Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Provides instructions for building the Go project, including installing dependencies, building for development, running tests, and cleaning build artifacts. Assumes Go 1.21+ and Make are installed. ```bash # Install dependencies make deps # Build for development make dev # Run tests make test # Clean build artifacts make clean ``` -------------------------------- ### Automated Installation Scripts Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Provides shell commands for automatically installing the thanhlv-encryption-decryption tool on Linux, macOS, and Windows. Users can install the latest version or a specific version using `curl` for Linux/macOS and PowerShell for Windows. An example command to verify the installation is also included. ```bash # Linux/macOS - Install latest version curl -sSL https://raw.githubusercontent.com/thanhlv-com/thanhlv-encryption-decryption/main/install.sh | bash # Linux/macOS - Install specific version curl -sSL https://raw.githubusercontent.com/thanhlv-com/thanhlv-encryption-decryption/main/install.sh | bash -s -- v1.1.0 # Windows PowerShell (as Administrator) - Install latest PowerShell -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/thanhlv-com/thanhlv-encryption-decryption/main/install.ps1'))" # Windows PowerShell - Install specific version $env:VERSION='v1.2.0'; PowerShell -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/thanhlv-com/thanhlv-encryption-decryption/main/install.ps1'))" # Verify installation thanhlv-ed keygen -a aes-256-cbc -b # Output: Generated AES-256-CBC key (base64): ... ``` -------------------------------- ### Automated Installation Scripts for Encryption/Decryption Tool Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Scripts to automatically install the encryption/decryption tool. They detect the platform, download the correct binary, install it to the system path, and verify the installation. Supports installing the latest version or a specific version. ```bash # Install latest version curl -sSL https://raw.githubusercontent.com/thanhlv-com/thanhlv-encryption-decryption/main/install.sh | bash # Install specific version curl -sSL https://raw.githubusercontent.com/thanhlv-com/thanhlv-encryption-decryption/main/install.sh | bash -s -- v1.1.0 ``` ```powershell # Install latest version PowerShell -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/thanhlv-com/thanhlv-encryption-decryption/main/install.ps1'))" # Install specific version $env:VERSION='v1.2.0'; PowerShell -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/thanhlv-com/thanhlv-encryption-decryption/main/install.ps1'))" ``` -------------------------------- ### RSA Encryption and Decryption Workflow Example Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Demonstrates a complete workflow for RSA encryption and decryption. It includes generating an RSA key pair, encrypting data with the public key, and decrypting with the private key. ```bash # 1. Generate RSA key pair ./thanhlv-ed keygen -a rsa -b # Outputs private and public keys in base64 # 2. Encrypt with public key ./thanhlv-ed encrypt -a rsa -k "" -t "Confidential data" # 3. Decrypt with private key ./thanhlv-ed decrypt -a rsa -k "" -t "" ``` -------------------------------- ### Go API: Implement and Register Custom Encryption Algorithms Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Illustrates how to extend the encryption tool by implementing the `CryptoProvider` interface and registering the new algorithm. This involves creating a new struct with `Encrypt`, `Decrypt`, and `GenerateKey` methods, and then updating the `NewCryptoProvider` function in `pkg/crypto/init.go` to recognize the new algorithm name. The example uses a simple XOR operation for demonstration. ```go // 1. Create new algorithm in pkg/crypto/myalgo.go package crypto import ( "crypto/rand" "fmt" "strings" ) type MyCustomProvider struct{} func (m *MyCustomProvider) Encrypt(data []byte, key []byte) ([]byte, error) { // Your encryption logic here result := make([]byte, len(data)) for i, b := range data { result[i] = b ^ key[i%len(key)] // Example: simple XOR } return result, nil } func (m *MyCustomProvider) Decrypt(data []byte, key []byte) ([]byte, error) { // Your decryption logic here result := make([]byte, len(data)) for i, b := range data { result[i] = b ^ key[i%len(key)] } return result, nil } func (m *MyCustomProvider) GenerateKey() ([]byte, error) { key := make([]byte, 32) if _, err := rand.Read(key); err != nil { return nil, fmt.Errorf("failed to generate key: %w", err) } return key, nil } // 2. Register in pkg/crypto/init.go // Assuming CryptoProvider, AESProvider, RSAProvider are defined elsewhere type CryptoProvider interface { Encrypt(data []byte, key []byte) ([]byte, error) Decrypt(data []byte, key []byte) ([]byte, error) GenerateKey() ([]byte, error) } type AESProvider struct {} type RSAProvider struct {} func NewCryptoProvider(algorithm string) (CryptoProvider, error) { switch strings.ToLower(algorithm) { case "aes-256-cbc": return &AESProvider{}, nil case "rsa": return &RSAProvider{}, nil case "my-custom-algo": return &MyCustomProvider{}, nil default: return nil, fmt.Errorf("unsupported algorithm: %s", algorithm) } } // 3. Use via CLI // ./thanhlv-ed keygen -a my-custom-algo -b // ./thanhlv-ed encrypt -a my-custom-algo -k "base64key" -t "Hello" // ./thanhlv-ed decrypt -a my-custom-algo -k "base64key" -t "encrypted" ``` -------------------------------- ### AES Encryption and Decryption Workflow Example Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md A complete workflow demonstrating AES-256-CBC encryption and decryption. It covers key generation, encrypting text using both key flag and environment variable, and decrypting text similarly. ```bash # 1. Generate a key ./thanhlv-ed keygen -a aes-256-cbc -b # Output: Generated AES-256-CBC key (base64): # 2. Encrypt text using key flag ./thanhlv-ed encrypt -a aes-256-cbc -k "MTExZHZzZHZzeGN2eGN2" -t "Secret message" # Output: Encrypted text (base64): # 2. Alternative: Encrypt text using environment variable export MY_AES_KEY="MTExZHZzZHZzeGN2eGN2" ./thanhlv-ed encrypt -a aes-256-cbc -e MY_AES_KEY -t "Secret message" # Output: Encrypted text (base64): # 3. Decrypt text using key flag ./thanhlv-ed decrypt -a aes-256-cbc -k "MTExZHZzZHZzeGN2eGN2" -t "J+FWPLdwO+N6BSaRo2o8vCUImk50kHYi4SkHrzeLP9Q=" # Output: Decrypted text: Secret message # 3. Alternative: Decrypt text using environment variable export MY_AES_KEY="MTExZHZzZHZzeGN2eGN2" ./thanhlv-ed decrypt -a aes-256-cbc -e MY_AES_KEY -t "J+FWPLdwO+N6BSaRo2o8vCUImk50kHYi4SkHrzeLP9Q=" # Output: Decrypted text: Secret message ``` -------------------------------- ### Base64 Encode AES Key Example Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Demonstrates how to generate a base64 encoded key for AES-256-CBC encryption. This is useful when the application requires a base64 encoded key string. ```bash echo -n "123df" | base64 # Output: MTIzZGY= ``` -------------------------------- ### Generate RSA Key Pair Example Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Generates an RSA key pair (private and public keys) in base64 format. This command is used to create the necessary keys for RSA encryption and decryption. ```bash # Generate RSA keys ./thanhlv-ed keygen -a rsa -b # This outputs both private and public keys in base64 format ``` -------------------------------- ### Go API: Apply and Reverse Byte Transfer Layer Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Demonstrates the use of the ApplyByteTransfer and ReverseByteTransfer functions from the crypto package. These functions add or subtract key bytes from data bytes as an additional obfuscation layer before encryption. The code shows examples with both short and long data to illustrate key rotation. ```go package main import ( "fmt" "thanhlv-encryption-decryption/pkg/crypto" ) func main() { originalData := []byte("Sensitive information") key := []byte("secret") // Apply byte transfer (adds key bytes to data) transferred := crypto.ApplyByteTransfer(originalData, key) fmt.Printf("Original: %s\n", originalData) fmt.Printf("Transferred (hex): %x\n", transferred) // Reverse byte transfer (subtracts key bytes from data) reversed := crypto.ReverseByteTransfer(transferred, key) fmt.Printf("Reversed: %s\n", reversed) // Output: Reversed: Sensitive information // Demonstrates rotation through key bytes longData := []byte("This is a much longer message that will rotate through the key multiple times") transferred = crypto.ApplyByteTransfer(longData, key) reversed = crypto.ReverseByteTransfer(transferred, key) fmt.Printf("Long data match: %v\n", string(reversed) == string(longData)) // Output: Long data match: true } ``` -------------------------------- ### Build Encryption/Decryption Tool from Source Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Instructions for building the encryption/decryption tool from its source code repository. This method allows for customization or building for specific environments. It requires Git and Make. ```bash # Clone the repository git clone cd thanhlv-encryption-decryption # Build for current platform make build # build-all for all platforms make build-all ``` -------------------------------- ### Go API: CryptoProvider Interface Usage Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Demonstrates the usage of the generic CryptoProvider interface in Go. It initializes an AES provider, generates a key, encrypts data, and then decrypts it. Requires the 'thanhlv-encryption-decryption/pkg/crypto' package. ```go package main import ( "encoding/base64" "fmt" "thanhlv-encryption-decryption/pkg/crypto" ) func main() { // Initialize AES provider provider, err := crypto.NewCryptoProvider("aes-256-cbc") if err != nil { panic(err) } // Generate a new key key, err := provider.GenerateKey() if err != nil { panic(err) } fmt.Printf("Generated key (base64): %s\n", base64.StdEncoding.EncodeToString(key)) // Encrypt data plaintext := []byte("Hello World!") ciphertext, err := provider.Encrypt(plaintext, key) if err != nil { panic(err) } fmt.Printf("Encrypted (base64): %s\n", base64.StdEncoding.EncodeToString(ciphertext)) // Decrypt data decrypted, err := provider.Decrypt(ciphertext, key) if err != nil { panic(err) } fmt.Printf("Decrypted: %s\n", string(decrypted)) // Output: Decrypted: Hello World! } ``` -------------------------------- ### RSA File Encryption/Decryption with CLI Tool Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Commands for encrypting and decrypting files using RSA with the command-line tool. Encryption utilizes the public key, and decryption requires the private key. Keys can be supplied via flags or environment variables. The encrypted file will have a .encrypted extension. ```bash # Encrypt file with public key (key flag) ./thanhlv-ed encrypt -a rsa -k "" -f document.pdf # Encrypt file with public key (environment variable) export RSA_PUBLIC_KEY="" ./thanhlv-ed encrypt -a rsa -e RSA_PUBLIC_KEY -f document.pdf # Decrypt file with private key (key flag) ./thanhlv-ed decrypt -a rsa -k "" -f document.pdf.encrypted ``` -------------------------------- ### RSA Text Encryption/Decryption with CLI Tool Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Commands for encrypting and decrypting text using RSA with the command-line tool. Encryption uses the public key, and decryption uses the private key. Keys can be provided via flags or environment variables. Input and output are Base64 encoded. ```bash # Encrypt with public key (key flag) ./thanhlv-ed encrypt -a rsa -k "" -t "Hello RSA World!" # Encrypt with public key (environment variable) export RSA_PUBLIC_KEY="" ./thanhlv-ed encrypt -a rsa -e RSA_PUBLIC_KEY -t "Hello RSA World!" # Decrypt with private key (key flag) ./thanhlv-ed decrypt -a rsa -k "" -t "" # Decrypt with private key (environment variable) export RSA_PRIVATE_KEY="" ./thanhlv-ed decrypt -a rsa -e RSA_PRIVATE_KEY -t "" ``` -------------------------------- ### Generate Encryption Keys with CLI Tool Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Command-line interface commands to generate encryption keys for AES-256-CBC and RSA algorithms. The tool supports outputting keys in Base64 format, which is convenient for direct use or storage. ```bash # Generate AES-256-CBC key (outputs base64) ./thanhlv-ed keygen -a aes-256-cbc -b # Generate RSA key pair ./thanhlv-ed keygen -a rsa -b ``` -------------------------------- ### AES-256-CBC File Encryption/Decryption with CLI Tool Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Commands for encrypting and decrypting files using AES-256-CBC with the command-line tool. Supports providing the key directly via a flag or through an environment variable. The encrypted file will have a .encrypted extension. ```bash # Encrypt file with key flag ./thanhlv-ed encrypt -a aes-256-cbc -k "MTIzZGY=" -f input.txt # Encrypt file with environment variable export ENCRYPTION_KEY="MTIzZGY=" ./thanhlv-ed encrypt -a aes-256-cbc -e ENCRYPTION_KEY -f input.txt # Decrypt file with key flag ./thanhlv-ed decrypt -a aes-256-cbc -k "MTIzZGY=" -f input.txt.encrypted # Decrypt file with environment variable export ENCRYPTION_KEY="MTIzZGY=" ./thanhlv-ed decrypt -a aes-256-cbc -e ENCRYPTION_KEY -f input.txt.encrypted ``` -------------------------------- ### Encrypt File with RSA Public Key (CLI) Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Encrypts a file using the RSA algorithm with a public key provided via an environment variable. The output is saved to a specified binary file. ```bash export RSA_PUBLIC_KEY="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t..." ./thanhlv-ed encrypt -a rsa -e RSA_PUBLIC_KEY -f report.docx -o encrypted_report.bin ``` -------------------------------- ### AES-256-CBC Text Encryption/Decryption with CLI Tool Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Commands for encrypting and decrypting text using AES-256-CBC with the command-line tool. Supports providing the key directly via a flag or securely through an environment variable. Input and output are Base64 encoded. ```bash # Encrypt text with key flag ./thanhlv-ed encrypt -a aes-256-cbc -k "" -t "Hello World!" # Encrypt text with environment variable export ENCRYPTION_KEY="" ./thanhlv-ed encrypt -a aes-256-cbc -e ENCRYPTION_KEY -t "Hello World!" # Decrypt text with key flag ./thanhlv-ed decrypt -a aes-256-cbc -k "" -t "" # Decrypt text with environment variable export ENCRYPTION_KEY="" ./thanhlv-ed decrypt -a aes-256-cbc -e ENCRYPTION_KEY -t "" # AES-256-CBC demo # Encrypt text ./thanhlv-ed encrypt -a aes-256-cbc -k "MTIzZGY=" -t "Hello World!" # Decrypt text ./thanhlv-ed decrypt -a aes-256-cbc -k "MTIzZGY=" -t "" ``` -------------------------------- ### Decrypt File with RSA Private Key from Environment (CLI) Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Decrypts a file using the RSA algorithm with a private key fetched from an environment variable. The decrypted content is saved to a specified output file. ```bash export RSA_PRIVATE_KEY="LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVkt..." ./thanhlv-ed decrypt -a rsa -e RSA_PRIVATE_KEY -f encrypted_report.bin -o report.docx ``` -------------------------------- ### Encrypt/Decrypt Text with RSA Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Encrypts and decrypts text using RSA-2048 with OAEP padding and SHA-256. Requires RSA public key for encryption and private key for decryption. Keys can be provided directly or through environment variables. Output is base64 encoded. ```bash # First generate RSA key pair ./thanhlv-ed keygen -a rsa -b # Save the output base64 keys for use # Encrypt text with public key ./thanhlv-ed encrypt -a rsa -k "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t..." -t "Confidential message" # Output: Encrypted text (base64): kR8mP2vQ9wX7nB6jC5tU3yL1fH4gD0zK... # Encrypt using environment variable export RSA_PUBLIC_KEY="LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t..." ./thanhlv-ed encrypt -a rsa -e RSA_PUBLIC_KEY -t "Secret data" # Output: Encrypted text (base64): 7xK9mN2pQ8vR5wT6yU1qL4fH0gD3jC8b... # Decrypt with private key ./thanhlv-ed decrypt -a rsa -k "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVkt..." -t "kR8mP2vQ9wX7nB6jC5tU3yL1fH4gD0zK..." # Output: Decrypted text: Confidential message # Decrypt using environment variable export RSA_PRIVATE_KEY="LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVkt..." ./thanhlv-ed decrypt -a rsa -e RSA_PRIVATE_KEY -t "7xK9mN2pQ8vR5wT6yU1qL4fH0gD3jC8b..." # Output: Decrypted text: Secret data ``` -------------------------------- ### Go API: RSA-2048 Provider Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Demonstrates direct usage of the RSAProvider in Go for RSA-2048 encryption. It supports OAEP padding, automatic chunking for large data, and handles PEM-encoded keys. Key pairs are generated, and messages are encrypted with the public key and decrypted with the private key. ```go package main import ( "encoding/base64" "fmt" "thanhlv-encryption-decryption/pkg/crypto" ) func main() { // Generate RSA key pair privateKey, publicKey, err := crypto.GenerateRSAKeyPair() if err != nil { panic(err) } fmt.Printf("Private Key (first 50 chars): %s...\n", string(privateKey[:50])) fmt.Printf("Public Key (first 50 chars): %s...\n", string(publicKey[:50])) rsa := &crypto.RSAProvider{} // Encrypt with public key message := []byte("This is a confidential message that needs RSA encryption") encrypted, err := rsa.Encrypt(message, publicKey) if err != nil { panic(err) } encryptedB64 := base64.StdEncoding.EncodeToString(encrypted) fmt.Printf("Encrypted length: %d bytes\n", len(encrypted)) // Decrypt with private key encryptedBytes, _ := base64.StdEncoding.DecodeString(encryptedB64) decrypted, err := rsa.Decrypt(encryptedBytes, privateKey) if err != nil { panic(err) } fmt.Printf("Decrypted: %s\n", string(decrypted)) // Output: Decrypted: This is a confidential message that needs RSA encryption } ``` -------------------------------- ### Go API: AES-256-CBC Provider Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Shows direct usage of the AESProvider in Go for AES-256-CBC encryption. It utilizes SHA-256 for key derivation from a password, generates a random Initialization Vector (IV), and employs PKCS#7 padding. Data is encoded to base64 for transport. ```go package main import ( "encoding/base64" "fmt" "thanhlv-encryption-decryption/pkg/crypto" ) func main() { aes := &crypto.AESProvider{} // Use a password-derived key (will be hashed to 256-bit) password := []byte("my-secret-password") // Encrypt sensitive data data := []byte("Account number: 1234567890") encrypted, err := aes.Encrypt(data, password) if err != nil { panic(err) } // Encode to base64 for storage or transmission encryptedB64 := base64.StdEncoding.EncodeToString(encrypted) fmt.Printf("Encrypted: %s\n", encryptedB64) // Decode from base64 encryptedBytes, _ := base64.StdEncoding.DecodeString(encryptedB64) // Decrypt data decrypted, err := aes.Decrypt(encryptedBytes, password) if err != nil { panic(err) } fmt.Printf("Decrypted: %s\n", string(decrypted)) // Output: Decrypted: Account number: 1234567890 } ``` -------------------------------- ### Decrypt File with Private Key (Environment Variable) Source: https://github.com/thanhlv-com/thanhlv-encryption-decryption/blob/main/README.md Decrypts a file using the RSA algorithm with the private key provided via an environment variable. Ensure the RSA_PRIVATE_KEY environment variable is set to your base64 encoded private key. ```bash export RSA_PRIVATE_KEY="" ./thanhlv-ed decrypt -a rsa -e RSA_PRIVATE_KEY -f document.pdf.encrypted ``` -------------------------------- ### Encrypt/Decrypt Text with AES-256-CBC Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Encrypts and decrypts text strings using AES-256-CBC with CBC mode, PKCS#7 padding, and a random Initialization Vector (IV). Supports providing keys directly via flags or through environment variables. Output is base64 encoded and can be saved to a file. ```bash # Encrypt text with direct key flag ./thanhlv-ed encrypt -a aes-256-cbc -k "MTIzZGY=" -t "Hello World!" # Output: Encrypted text (base64): J+FWPLdwO+N6BSaRo2o8vCUImk50kHYi4SkHrzeLP9Q= # Encrypt text using environment variable export ENCRYPTION_KEY="MTIzZGY=" ./thanhlv-ed encrypt -a aes-256-cbc -e ENCRYPTION_KEY -t "Sensitive data" # Output: Encrypted text (base64): 8xK2mN9pQ7vR5wT6yU1qL4fH0gD3jC8b # Decrypt text with direct key ./thanhlv-ed decrypt -a aes-256-cbc -k "MTIzZGY=" -t "J+FWPLdwO+N6BSaRo2o8vCUImk50kHYi4SkHrzeLP9Q=" # Output: Decrypted text: Hello World! # Decrypt with environment variable and save to file export ENCRYPTION_KEY="MTIzZGY=" ./thanhlv-ed decrypt -a aes-256-cbc -e ENCRYPTION_KEY -t "8xK2mN9pQ7vR5wT6yU1qL4fH0gD3jC8b" -o output.txt # Output: Decrypted text written to: output.txt ``` -------------------------------- ### Encrypt/Decrypt Files with RSA Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Encrypts and decrypts files using RSA. The tool handles large files by chunking the data. It requires the RSA public key for encryption and the private key for decryption. Output files are named with a '.encrypted' extension. ```bash # Encrypt file with public key ./thanhlv-ed encrypt -a rsa -k "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t..." -f contract.pdf # Output: File encrypted and saved to: contract.pdf.encrypted # Note: Decryption commands for RSA files are not explicitly shown but would follow a similar pattern to text decryption using the private key. ``` -------------------------------- ### Encrypt/Decrypt Files with AES-256-CBC Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Encrypts and decrypts files of any size using AES-256-CBC. The tool automatically generates output filenames by appending '.encrypted' for encryption and removing it for decryption. Keys can be provided directly or via environment variables. ```bash # Encrypt file with direct key (creates document.pdf.encrypted) ./thanhlv-ed encrypt -a aes-256-cbc -k "MTIzZGY=" -f document.pdf # Output: File encrypted and saved to: document.pdf.encrypted # Encrypt with custom output name using environment variable export ENCRYPTION_KEY="MTIzZGY=" ./thanhlv-ed encrypt -a aes-256-cbc -e ENCRYPTION_KEY -f data.json -o secure.bin # Output: File encrypted and saved to: secure.bin # Decrypt file (automatically removes .encrypted extension) ./thanhlv-ed decrypt -a aes-256-cbc -k "MTIzZGY=" -f document.pdf.encrypted # Output: File decrypted and saved to: document.pdf # Decrypt with custom output name export ENCRYPTION_KEY="MTIzZGY=" ./thanhlv-ed decrypt -a aes-256-cbc -e ENCRYPTION_KEY -f secure.bin -o restored.json # Output: File decrypted and saved to: restored.json ``` -------------------------------- ### Generate AES-256-CBC or RSA Keys Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Generates encryption keys for AES-256-CBC or RSA algorithms. Supports base64 output and custom filenames for RSA key pairs. This command is essential for obtaining the necessary keys before performing encryption or decryption operations. ```bash # Generate AES-256-CBC key in base64 format ./thanhlv-ed keygen -a aes-256-cbc -b # Output: Generated AES-256-CBC key (base64): zR3kP9mQ7wX2vB5nJ8cT6yU1qL4fH0gD # Generate RSA key pair with custom file names ./thanhlv-ed keygen -a rsa -p my_private.pem -u my_public.pem -b # Output: # RSA key pair generated: # Private key: my_private.pem # Public key: my_public.pem # Private key (base64): LS0tLS1CRUdJTi... # Public key (base64): LS0tLS1CRUdJTi... # Generate RSA with default filenames (private_key_rsa.pem, public_key_rsa.pem) ./thanhlv-ed keygen -a rsa ``` -------------------------------- ### Decrypt File with RSA Private Key (CLI) Source: https://context7.com/thanhlv-com/thanhlv-encryption-decryption/llms.txt Decrypts an encrypted file using the RSA algorithm with a private key provided directly as a string. The decrypted content is saved to a file. ```bash ./thanhlv-ed decrypt -a rsa -k "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVkt..." -f contract.pdf.encrypted ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.