-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (44 loc) · 1.7 KB
/
Program.cs
File metadata and controls
50 lines (44 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using CommandLine;
using ConfigCrypter.Console.Options;
using DevAttic.ConfigCrypter;
using DevAttic.ConfigCrypter.CertificateLoaders;
using DevAttic.ConfigCrypter.ConfigCrypters.Json;
using DevAttic.ConfigCrypter.Crypters;
namespace ConfigCrypter.Console
{
class Program
{
static void Main(string[] args)
{
Parser.Default.ParseArguments<EncryptOptions, DecryptOptions>(args)
.WithParsed<EncryptOptions>(opts =>
{
var crypter = CreateCrypter(opts);
crypter.EncryptKeyInFile(opts.ConfigFile, opts.Key, opts.Separator);
})
.WithParsed<DecryptOptions>(opts =>
{
var crypter = CreateCrypter(opts);
crypter.DecryptKeyInFile(opts.ConfigFile, opts.Key, opts.Separator);
});
}
private static ConfigFileCrypter CreateCrypter(CommandlineOptions options)
{
ICertificateLoader certLoader = null;
if (!string.IsNullOrEmpty(options.CertificatePath))
{
certLoader = new FilesystemCertificateLoader(options.CertificatePath, options.CertificatePassword);
}
else if (!string.IsNullOrEmpty(options.CertSubjectName))
{
certLoader = new StoreCertificateLoader(options.CertSubjectName);
}
var configCrypter = new JsonConfigCrypter(new RSACrypter(certLoader));
var fileCrypter = new ConfigFileCrypter(configCrypter, new ConfigFileCrypterOptions()
{
ReplaceCurrentConfig = options.Replace
});
return fileCrypter;
}
}
}