From 707bdb667004c4fdd3ee9886fa3d7002fdf53404 Mon Sep 17 00:00:00 2001 From: Patrick Scheid Date: Fri, 12 Jun 2026 04:43:44 +0200 Subject: [PATCH] Use a cryptographic RNG for auto-generated passphrases System.Random is predictable; the generated passphrase is the sole secret protecting the encrypted file. --- Age.Cli/AgeCommand.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Age.Cli/AgeCommand.cs b/Age.Cli/AgeCommand.cs index 9fb0ba6..4523eef 100644 --- a/Age.Cli/AgeCommand.cs +++ b/Age.Cli/AgeCommand.cs @@ -1,3 +1,4 @@ +using System.Security.Cryptography; using System.Text; using Age.Format; using Age.Plugin; @@ -188,14 +189,15 @@ private static string ReadPassphrase(string prompt) private static string GeneratePassphrase() { - var rng = new Random(); + // This passphrase is the sole secret protecting the encrypted file, so it + // must come from a cryptographically secure RNG — never System.Random. var parts = new string[10]; for (var i = 0; i < 10; i++) { var chars = new char[6]; for (var j = 0; j < 6; j++) - chars[j] = (char)('a' + rng.Next(26)); + chars[j] = (char)('a' + RandomNumberGenerator.GetInt32(26)); parts[i] = new string(chars); }