public static RSAParameters ImportRSAPublicKey(string buf) { RSAParameters rsaParameters = new RSACryptoServiceProvider().ExportParameters(false); byte[] buffer = Convert.FromBase64String(string.Join(string.Empty, ((IEnumerable <string>)buf.Split(Environment.NewLine.ToArray <char>())).Where <string>(line => !line.Trim().StartsWith("-")).ToArray <string>())); MemoryStream memoryStream = new MemoryStream(); memoryStream.Write(buffer, 0, buffer.Length); memoryStream.Seek(0L, SeekOrigin.Begin); using (BinaryReader stream = new BinaryReader(memoryStream)) { if (stream.ReadByte() != 48) { return(rsaParameters); } UASecurity.DecodeLength(stream); byte[] numArray = UASecurity.DecodeIntBigEndian(stream); if (numArray.Length != 1 || numArray[0] > 0) { return(rsaParameters); } rsaParameters.Modulus = UASecurity.DecodeIntBigEndian(stream); rsaParameters.Exponent = UASecurity.DecodeIntBigEndian(stream); UASecurity.DecodeIntBigEndian(stream); UASecurity.DecodeIntBigEndian(stream); UASecurity.DecodeIntBigEndian(stream); UASecurity.DecodeIntBigEndian(stream); UASecurity.DecodeIntBigEndian(stream); UASecurity.DecodeIntBigEndian(stream); } return(rsaParameters); }