Example #1
0
        public static Key getPublicKeyfromPrivateKey(string privateKey)
        {
            RSACryptoServiceProvider rsa = PEM.ImportPrivateKey(privateKey);

            return(new Key()
            {
                privateKey = privateKey, publicKey = PEM.ExportPublicKey(rsa), keySize = rsa.KeySize
            });
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }