Convert TOML to BASE64
Max file size 100mb.
TOML vs BASE64 Format Comparison
| Aspect | TOML (Source Format) | BASE64 (Target Format) |
|---|---|---|
| Format Overview |
TOML
Tom's Obvious Minimal Language
A minimal configuration file format created by Tom Preston-Werner. Uses key = value pairs with [section] headers and strictly typed values. Designed to be easy to read and unambiguous to parse. Standard configuration format for Rust (Cargo.toml) and Python (pyproject.toml) ecosystems. Configuration Format Human-Readable |
BASE64
Base64 Binary-to-Text Encoding
A binary-to-text encoding scheme that represents binary data using 64 ASCII characters (A-Z, a-z, 0-9, +, /). Defined in RFC 4648, it encodes every 3 bytes into 4 ASCII characters. Used universally for transmitting data through text-only channels such as email, URLs, and API payloads. Encoding Scheme Transport Safe |
| Technical Specifications |
Structure: Key-value pairs with [sections]
Encoding: UTF-8 required Data Types: Strings, integers, floats, booleans, dates, arrays, tables Nesting: [section.subsection] dot notation Extensions: .toml |
Character Set: A-Z, a-z, 0-9, +, / (64 chars)
Padding: = character for alignment Size Overhead: ~33% larger than source Standard: RFC 4648 / RFC 2045 Variants: Standard, URL-safe, MIME |
| Syntax Examples |
TOML configuration data: [server] host = "localhost" port = 8080 [database] url = "postgres://db:5432" pool_size = 10 |
Base64-encoded output: W3NlcnZlcl0KaG9zdCA9ICJs b2NhbGhvc3QiCnBvcnQgPSA4 MDgwCgpbZGF0YWJhc2VdCnVy bCA9ICJwb3N0Z3JlczovL2Ri OjU0MzIiCnBvb2xfc2l6ZSA9 IDEw |
| Content Support |
|
|
| Advantages |
|
|
| Disadvantages |
|
|
| Common Uses |
|
|
| Best For |
|
|
| Version History |
Created: 2013 by Tom Preston-Werner
Current Version: TOML v1.0.0 (2021) Status: Stable, formally specified Evolution: Active community development |
Origin: 1987 (Privacy Enhanced Mail)
RFC 2045: 1996 (MIME standard) RFC 4648: 2006 (current standard) Status: Universal standard |
| Software Support |
Rust/Cargo: Native support
Python: tomllib (3.11+), tomli JavaScript: @iarna/toml, smol-toml Other: Go, Java, C#, Ruby libraries |
Python: base64 module (built-in)
JavaScript: btoa()/atob(), Buffer CLI: base64 command (Linux/macOS) Other: Every programming language |
Why Convert TOML to BASE64?
Converting TOML configuration files to Base64 encoding is essential when you need to transmit configuration data through channels that only support ASCII text. Base64 encoding ensures that your TOML content, including any special characters, newlines, and Unicode text, arrives intact without corruption or modification by intermediate systems.
One of the most common use cases is storing TOML configuration in environment variables or Kubernetes secrets. Many deployment platforms and container orchestration systems require configuration values to be Base64-encoded. By converting your Cargo.toml, pyproject.toml, or application config to Base64, you can safely embed the entire configuration as a single environment variable or secret value.
Base64-encoded TOML is also valuable for API communication. When building microservices that need to exchange configuration data, Base64 encoding allows you to embed TOML content within JSON payloads, HTTP headers, or URL parameters without worrying about escaping issues. The receiving service simply decodes the Base64 string to recover the original TOML content.
The encoding process is lossless and reversible: the original TOML file can be perfectly reconstructed by decoding the Base64 output. This makes it ideal for configuration backup, transfer between systems, and any scenario where you need to guarantee exact content preservation through text-only transport channels.
Key Benefits of Converting TOML to BASE64:
- Transport Safety: No special character issues in any transmission channel
- Kubernetes Secrets: Store TOML configs as Base64-encoded secrets
- Environment Variables: Embed entire config files in a single env var
- API Payloads: Include TOML data in JSON/XML without escaping
- Lossless Encoding: Perfect round-trip preservation of content
- Universal Compatibility: Base64 is supported in every language and platform
- Data Integrity: Prevents corruption during transmission
Practical Examples
Example 1: Kubernetes Secret Configuration
Input TOML file (app-config.toml):
[database] host = "db.production.internal" port = 5432 name = "app_production" ssl_mode = "require" [cache] host = "redis.production.internal" port = 6379 ttl = 3600
Output BASE64 (for Kubernetes secret):
W2RhdGFiYXNlXQpob3N0ID0gImRiLnByb2R1Y3Rpb24u aW50ZXJuYWwiCnBvcnQgPSA1NDMyCm5hbWUgPSAiYXBw X3Byb2R1Y3Rpb24iCnNzbF9tb2RlID0gInJlcXVpcmUi CgpbY2FjaGVdCmhvc3QgPSAicmVkaXMucHJvZHVjdGlv bi5pbnRlcm5hbCIKcG9ydCA9IDYzNzkKdHRsID0gMzYw MA== # Use in Kubernetes: # kubectl create secret generic app-config \ # --from-literal=config=<base64-output>
Example 2: Environment Variable Embedding
Input TOML file (deploy.toml):
[build] command = "npm run build" publish = "dist" [build.environment] NODE_VERSION = "18" API_URL = "https://api.example.com" [[redirects]] from = "/app/*" to = "/index.html" status = 200
Output BASE64 (for environment variable):
W2J1aWxkXQpjb21tYW5kID0gIm5wbSBydW4gYnVpbGQi CnB1Ymxpc2ggPSAiZGlzdCIKCltidWlsZC5lbnZpcm9u bWVudF0KTk9ERV9WRVJTSU9OID0gIjE4IgpBUElfVVJM ID0gImh0dHBzOi8vYXBpLmV4YW1wbGUuY29tIgoKW1ty ZWRpcmVjdHNdXQpmcm9tID0gIi9hcHAvKiIKdG8gPSAi L2luZGV4Lmh0bWwiCnN0YXR1cyA9IDIwMA== # Set as env var: # export DEPLOY_CONFIG="W2J1aWxkXQ..." # Decode: echo $DEPLOY_CONFIG | base64 -d
Example 3: API Payload Configuration
Input TOML file (service.toml):
[service] name = "payment-gateway" version = "2.0.0" timeout = 30 [service.endpoints] process = "/api/v2/process" refund = "/api/v2/refund" status = "/api/v2/status"
Output BASE64 (for API transmission):
W3NlcnZpY2VdCm5hbWUgPSAicGF5bWVudC1nYXRld2F5
IgpudmVyc2lvbiA9ICIyLjAuMCIKdGltZW91dCA9IDMw
CgpbcGVydmljZS5lbmRwb2ludHNdCnByb2Nlc3MgPSAi
L2FwaS92Mi9wcm9jZXNzIgpyZWZ1bmQgPSAiL2FwaS92
Mi9yZWZ1bmQiCnN0YXR1cyA9ICIvYXBpL3YyL3N0YXR1
cyI=
# Embed in JSON API call:
# {"config": "W3NlcnZpY2VdCm5hbWUg...", "format": "toml"}
Frequently Asked Questions (FAQ)
Q: What is Base64 encoding?
A: Base64 is a binary-to-text encoding scheme defined in RFC 4648. It represents data using 64 ASCII characters (A-Z, a-z, 0-9, +, /) plus = for padding. It encodes every 3 bytes of input into 4 ASCII characters, resulting in a ~33% size increase. Base64 is used to safely transmit data through text-only channels.
Q: Can I decode Base64 back to the original TOML?
A: Yes! Base64 encoding is completely lossless and reversible. You can decode the Base64 string back to the exact original TOML content using any Base64 decoder. In the command line, use `base64 -d` (Linux/macOS) or `certutil -decode` (Windows). Every programming language has built-in Base64 decode functions.
Q: Why not just embed the TOML directly in environment variables?
A: TOML files contain newlines, special characters (brackets, quotes, equals signs), and potentially Unicode text that can cause issues with environment variable parsing. Base64 encoding produces a single continuous string of safe ASCII characters that works reliably in all shell environments and configuration systems.
Q: How much larger is the Base64 output compared to the TOML input?
A: Base64 encoding increases the size by approximately 33%. A 1KB TOML file becomes approximately 1.33KB when Base64-encoded. For configuration files, which are typically small, this overhead is negligible. The tradeoff of slightly larger size for transport safety is well worth it.
Q: Is Base64 encoding the same as encryption?
A: No! Base64 is an encoding scheme, not encryption. Anyone can decode a Base64 string to read the original content. It provides no security or confidentiality. If you need to protect sensitive TOML configuration values (passwords, API keys), use proper encryption before or after Base64 encoding.
Q: How do Kubernetes secrets use Base64?
A: Kubernetes requires secret values to be Base64-encoded in YAML manifests. By converting your TOML config to Base64, you can store the entire configuration file as a Kubernetes secret. The application pod then decodes the Base64 value at runtime to access the original TOML configuration.
Q: What is the difference between standard Base64 and URL-safe Base64?
A: Standard Base64 uses + and / characters, which have special meanings in URLs. URL-safe Base64 replaces these with - and _ respectively. If you need to include the encoded TOML in URL parameters, use the URL-safe variant to avoid encoding issues.
Q: Can I use Base64-encoded TOML in Docker configurations?
A: Yes! Base64-encoded TOML works well in Docker environments. You can pass it as an environment variable in docker-compose.yml or Dockerfile, and your application decodes it at startup. This is a common pattern for injecting configuration into containerized applications without mounting config files.