Beispiel #1
0
        static RSA CreateRSAByXmlKey(Stream key_xml)
        {
            var rsa = RSA.Create();

            rsa.ImportParameters(RSAHelper.DeserializeRSAParameters(key_xml));
            return(rsa);
        }
Beispiel #2
0
        static RSA CreateRSAByStringKey(string?publicKey_str, string?privateKey_str)
        {
            if (string.IsNullOrWhiteSpace(publicKey_str) && string.IsNullOrWhiteSpace(privateKey_str))
            {
                throw new ArgumentException("No keys.");
            }

            var rsa = RSA.Create();

            if (!string.IsNullOrEmpty(publicKey_str))
            {
                var publicKey_bytes = RSAHelper.DeserializeRSAKey(publicKey_str);
                rsa.ImportRSAPublicKey(new ReadOnlySpan <byte>(publicKey_bytes), out _);
            }
            if (!string.IsNullOrEmpty(privateKey_str))
            {
                var privateKey_bytes = RSAHelper.DeserializeRSAKey(privateKey_str);
                rsa.ImportRSAPrivateKey(new ReadOnlySpan <byte>(privateKey_bytes), out _);
            }
            return(rsa);
        }