I have RSA public key encoded in Base64. After decoding I can get RSA public key like:
-----BEGIN PUBLIC KEY----- XXXXXXXXXXXXXXXXXXXXXXX -----END PUBLIC KEY-----
Now I need to import this key into RSACryptoServiceProvider. I was looking for solution but wasn't able to find anything working. From pieces I found, I created such code sample
    public static string Encrypt(string input, string base64PublicKey)
    {
        var rsa = new RSACryptoServiceProvider();
        var byteKey = System.Convert.FromBase64String(base64PublicKey);
        var byteInput = Encoding.UTF8.GetBytes(input);
        var parameters = rsa.ExportParameters(false);
        parameters.Modulus = byteKey;
        rsa.ImportParameters(parameters);
        var bytesEncrypted = rsa.Encrypt(byteInput, false);
        var result = System.Convert.ToBase64String(bytesEncrypted);
        return result;
    }
I suppose it is not working correctly, because I always get response with error from the system I'm integrating with.
Is it a correct way to import public key? If not how should I do it?