public PrivatePublicKeyHelper(bool generateNewKeys) { if (generateNewKeys) { keys = EncryptorRSA.GenerateKeys(KeySize); } }
public static EncryptorKeys GenerateKeys(int keySize) { if (keySize % 2 != 0 || keySize < 512) { throw new Exception("Key should be multiple of two and greater than 512."); } var response = new EncryptorKeys(); using (var provider = new RSACryptoServiceProvider(keySize)) { response.PublicKey = provider.ToXmlString(false); response.PrivateKey = provider.ToXmlString(true); } return(response); }