System.Security.Cryptography.RSA.Create C# (CSharp) Method

Create() public static method

public static Create ( ) : RSA
return RSA
        public static new RSA Create()
        {
            return new RSAImplementation.RSACng();
        }

Same methods

RSA::Create ( String algName ) : RSA

Usage Example

Beispiel #1
0
            public static Rsa Create(ReadOnlySpan <Byte> key, RSAKeyType type = DefaultRSAKeyType, RSAParameters?parameters = null)
            {
                Rsa rsa = parameters is null?Rsa.Create() : Rsa.Create(parameters.Value);

                if (rsa is null)
                {
                    throw new FactoryException("Unknown exception");
                }

                Int32 size = key.Length * 8;

                try
                {
                    rsa.KeySize = size;
                }
                catch (CryptographicException)
                {
                    throw new ArgumentException($@"Invalid key size: {size}", nameof(key));
                }

                switch (type)
                {
                case RSAKeyType.RSA:
                    rsa.ImportRSAPrivateKey(key);
                    break;

                case RSAKeyType.Pkcs8:
                    rsa.ImportPkcs8PrivateKey(key);
                    break;

                case RSAKeyType.RSAPublic:
                    rsa.ImportRSAPublicKey(key);
                    break;

                case RSAKeyType.SubjectPublic:
                    rsa.ImportSubjectPublicKeyInfo(key);
                    break;

                default:
                    throw new NotSupportedException();
                }

                return(rsa);
            }
All Usage Examples Of System.Security.Cryptography.RSA::Create