public static void CreateKey() { Global glob = new Global(); glob.UnlockBundle("Anything for 30-day trial"); SshKey key = new SshKey(); Rsa rsaKey = new Rsa(); rsaKey.GenerateKey(1024); _privateKey = rsaKey.ExportPrivateKeyObj(); Console.WriteLine("Private Key: " + rsaKey.ExportPrivateKey()); _publicKey = rsaKey.ExportPublicKey(); Console.WriteLine("Public Key: " + _publicKey); using (ConsulClient consulClient = new ConsulClient()) { String url = Constants.BASE_URL + ":" + Constants.CONSUL_PORT; Console.WriteLine("Consul URL: " + url); consulClient.Config.Address = new Uri(url); var putPair = new KVPair("publickey") { Value = Encoding.UTF8.GetBytes(_publicKey) }; var putAttempt = consulClient.KV.Put(putPair).Result; Console.WriteLine("Put Result: " + JsonConvert.SerializeObject(putAttempt)); } _isCreated = true; }
public static void GenKeyPair() { const int byteSize = 2048 / 8; Rsa.GenerateKey(byteSize, out var pk, out var sk); var pks = "public readonly static byte[] PkData = new byte[]{\n "; for (var i = 0; i < pk.Length; ++i) { pks += $"{pk[i]},"; if (i % 20 == 19) { pks += "\n "; } } pks += "\n};"; var sks = "public readonly static byte[] SkData = new byte[]{\n "; for (var i = 0; i < sk.Length; ++i) { sks += $"{sk[i]},"; if (i % 20 == 19) { sks += "\n "; } } sks += "\n};"; Console.WriteLine(pks); Console.WriteLine(sks); }
public void Run(string raw) { const int byteSize = 2048 / 8; raw = raw + raw; Rsa.GenerateKey(byteSize, out var pk, out var sk); Utils.WriteByteArray(pk, "pk"); Utils.WriteByteArray(sk, "sk"); var e = Encoding.UTF8; Utils.WriteByteArray(e.GetBytes(raw), "raw"); var secret = Rsa.Encrypt(e.GetBytes(raw), pk); Utils.WriteByteArray(secret, "secret"); var real = Rsa.Decrypt(secret, pk, sk); Console.WriteLine("Real: " + e.GetString(real)); if (!raw.Equals(e.GetString(real))) { throw new Exception("Rsa Test Failed"); } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); Configuration = builder.Build(); var serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection); ServiceProvider = serviceCollection.BuildServiceProvider(); Client.SetLanguage(ChatDesktop.Properties.UserSettings.Default.Lang); Rsa.GenerateKey(); var mainWindow = ServiceProvider.GetRequiredService <AuthorizeWindow>(); mainWindow.DataContext = ServiceProvider.GetRequiredService <AuthorizeVM>(); mainWindow.Show(); }