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