The Lifecycle of a Cryptographic Key
Introduction
The Journey Begins: Birth Through Randomness
Why Randomness Matters
// ❌ WRONG - Predictable and insecure
void generateWeakKey() {
std::srand(std::time(nullptr)); // Predictable seed!
std::uint8_t buf[32];
for (auto& byte : buf)
byte = std::rand() % 256; // NOT cryptographically secure
}
// ✅ CORRECT - Cryptographically secure
SecretKey generateStrongKey() {
std::uint8_t buf[32];
beast::rngfill(buf, sizeof(buf), crypto_prng()); // CSPRNG
SecretKey sk{Slice{buf, sizeof(buf)}};
secure_erase(buf, sizeof(buf)); // Clean up
return sk;
}The Birth of a Secret Key
Where Randomness Comes From
Growth: From Secret to Public
The One-Way Function
Two Algorithms, Two Approaches
The Beauty of One-Way Functions
Alternative Path: Deterministic Generation
Why Deterministic Keys?
How Seeds Work
The Generator Pattern
From Key to Identity: Account IDs
The RIPESHA Double Hash
The Complete Lifecycle
Lifecycle Management: RAII and Secure Cleanup
Key Type Detection
Summary: The Key Lifecycle
Key Takeaways
Last updated

