public static Key getPublicKeyfromPrivateKey(string privateKey) { RSACryptoServiceProvider rsa = PEM.ImportPrivateKey(privateKey); return(new Key() { privateKey = privateKey, publicKey = PEM.ExportPublicKey(rsa), keySize = rsa.KeySize }); }
public static Key GenerateKeys(int keySize) { RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(keySize); Key newKey = new Key() { privateKey = PEM.ExportPrivateKey(rsa), publicKey = PEM.ExportPublicKey(rsa) }; return(newKey); }
public static Key ReadPrivateKey(Stream FileStream) { Key myKey = new Key(); using (FileStream) { using (StreamReader reader = new StreamReader(FileStream)) { myKey.privateKey = reader.ReadToEnd(); RSACryptoServiceProvider csp = PEM.ImportPrivateKey(myKey.privateKey); myKey.publicKey = PEM.ExportPublicKey(PEM.ImportPrivateKey(myKey.privateKey)); myKey.keySize = csp.KeySize; } } return(myKey); }