Skip to content

Commit

Permalink
RandomNumberGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
vijayshinva committed Dec 4, 2020
1 parent 3ffc685 commit 44931b1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Kryptos/Kryptos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ static async Task<int> Main(string[] args)
.WireUpHmacSha512Commands()
.WireUpSriCommands()
.WireUpOidCommands()
.WireUpPfxCommands();
.WireUpPfxCommands()
.WireUpRngCommands();

return await rootCommand.InvokeAsync(args);
}
Expand Down
52 changes: 52 additions & 0 deletions Kryptos/Kryptos/WireUpRngExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace Kryptos
{
public static class WireUpRngExtensions
{
public static RootCommand WireUpRngCommands(this RootCommand rootCommand)
{
var rngCommand = new Command("rng", "Random Number Generator");
rngCommand.AddOption(new Option<int>(new string[] { "--max", "-m" }, "Maximum (exclusive)"));
rngCommand.AddOption(new Option<FileInfo>(new string[] { "--output", "-o" }, "Output file path"));

rngCommand.Handler = CommandHandler.Create<int, FileInfo, IConsole>(async (max, output, console) =>
{
try
{
if (max <= 0)
{
max = int.MaxValue;
}
var random = RandomNumberGenerator.GetInt32(max);

if (output == null)
{
console.Out.WriteLine(random.ToString());
}
else
{
await File.WriteAllTextAsync(output.FullName, random.ToString()).ConfigureAwait(false);
}
}
catch (Exception ex)
{
console.Out.WriteLine(ex.Message);
return 22;
}
return 0;
});

rootCommand.AddCommand(rngCommand);

return rootCommand;
}
}
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ kryptos --help
```
kryptos oid -t 1.3.6.1.5.5.7.3.1
```
6. Encrypt text using a PFX certificate
```
kryptos pfx enc -ci MyCertificate.pfx -kt pfxPassword -t "The quick brown fox jumps over the lazy dog."
```
## Contributing
- Fork the repo on [GitHub][git-repo]
- Clone the project to your own machine
Expand Down

0 comments on commit 44931b1

Please sign in to comment.