public static void GenerateKeys() { int keySize = 4096; var keys = EncryptorRSA.GenerateKeys(keySize); StreamWriter publicKey = new StreamWriter("publickey"); publicKey.Write(keys.PublicKey); StreamWriter privateKey = new StreamWriter("privatekey"); privateKey.Write(keys.PrivateKey); publicKey.Close(); privateKey.Close(); }
public async Task RequestPublicKey() { var keyPair = EncryptorRSA.GenerateKeys(KeySize); if (KeyPairs.TryAdd(Context.ConnectionId, keyPair)) { Console.WriteLine($"Generated new key pair for client with ConnectionId '{Context.ConnectionId}:" + $"\n\tPublic key: {keyPair.PublicKey}" + $"\n\tPrivate key: {keyPair.PrivateKey}"); await Clients.Caller.SendAsync("PublicKey", keyPair.PublicKey); } }
static void Main(string[] args) { EncryptorRSAKeys key = EncryptorRSA.GenerateKeys(2048); string input = ""; input = Console.ReadLine(); string str = EncryptorRSA.EncryptText(input, key.PublicKey); Console.WriteLine("encrypt: " + str); Console.WriteLine("decrypt: " + EncryptorRSA.DecryptText(str, key.PrivateKey)); Console.WriteLine(EncryptorRSA.GetMaxDataLength(16384)); Console.ReadKey(); }
private static async Task RegenerateKeys() { while (true) { await Task.Delay(TimeSpan.FromMinutes(30)); foreach (var keyValue in KeyPairs) { var newPair = EncryptorRSA.GenerateKeys(KeySize); keyValue.Value.PublicKey = newPair.PublicKey; keyValue.Value.PrivateKey = newPair.PrivateKey; Console.WriteLine($"Generated new key pair for client with ConnectionId '{keyValue.Key}:" + $"\n\tPublic key: {keyValue.Value.PublicKey}" + $"\n\tPrivate key: {keyValue.Value.PrivateKey}"); await CallerClients.Caller.SendAsync("PublicKey", keyValue.Value.PublicKey); } } }