Goedel.Mesh.PublicKey.Generate C# (CSharp) Method

Generate() public static method

Generate a new key pair and return a PublicKey object for the public parameters.
public static Generate ( KeyType KeyType, CryptoAlgorithmID CryptoAlgorithmID ) : PublicKey
KeyType KeyType The mest key type.
CryptoAlgorithmID CryptoAlgorithmID The algorithm to generate keys for.
return PublicKey
        public static PublicKey Generate(KeyType KeyType, CryptoAlgorithmID CryptoAlgorithmID) {

            var CryptoProvider = CryptoCatalog.Default.GetAsymmetric(CryptoAlgorithmID);
            CryptoProvider.Generate(GetKeySecurity(KeyType));
            var KeyPair = CryptoProvider.KeyPair;

            var PublicKey = new PublicKey();
            PublicKey.KeyPair = KeyPair;
            

            if (KeyPair.GetType() == typeof(RSAKeyPair)) {
                PublicKey.PublicParameters = new PublicKeyRSA(KeyPair as RSAKeyPair);
                return PublicKey;
               }

            throw new Exception("Not found");
            }