/// <summary> /// Import RSA private key /// </summary> /// <param name="rsa"></param> /// <param name="privateKey"></param> /// <param name="bytesRead"></param> /// <exception cref="ArgumentNullException"></exception> public static void ImportRSAPrivateKey(this RSA rsa, ReadOnlySpan <byte> privateKey, out int bytesRead) { if (rsa is null) { throw new ArgumentNullException(nameof(rsa)); } bytesRead = privateKey.Length; var key = Convert.ToBase64String(privateKey.ToArray()); rsa.FromPkcs1PrivateString(key, out _); }