Exception in custom ctivity :RemoteException wrapping System.FormatException: Invalid length for a Base-64 char array or string

Hi all,
I have created a custom activity. The purpose of this activity is to encrypt password and convert it ToBase64string. I have tested code and it’s working fine in Visual studio. I have created a nuget Package from this and using into Uipath.
But when i tried my activity in uipath it’s not working.Showing error-

“RemoteException wrapping System.FormatException: Invalid length for a Base-64 char array or string.
at System.Convert.FromBase64_Decode(Char* startInputPtr,…”

My code is -

public string EncryptStringAES(string plainText, string sharedSecret)
{
if (string.IsNullOrEmpty(plainText))
throw new ArgumentNullException(“plainText”);
if (string.IsNullOrEmpty(sharedSecret))
throw new ArgumentNullException(“sharedSecret”);

        byte[] outStr; // Encrypted string to return
        string str_outStr;
        RijndaelManaged aesAlg = null; // RijndaelManaged object used to encrypt the data.

        try
        {
            // generate the key from the shared secret and the salt
            var key = new Rfc2898DeriveBytes(sharedSecret, _salt);

            // Create a RijndaelManaged object
            aesAlg = new RijndaelManaged();
            aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8);

            // Create a decryptor to perform the stream transform.
            var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

            // Create the streams used for encryption.
            using (var msEncrypt = new System.IO.MemoryStream())
            {
                // prepend the IV
                msEncrypt.Write(BitConverter.GetBytes(aesAlg.IV.Length), 0, sizeof(int));
                msEncrypt.Write(aesAlg.IV, 0, aesAlg.IV.Length);
                using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                {
                    using (var swEncrypt = new StreamWriter(csEncrypt))
                    {
                        //Write all data to the stream.
                        swEncrypt.Write(plainText);
                    }
                }

                outStr = msEncrypt.ToArray();
                str_outStr = Convert.ToBase64String(msEncrypt.ToArray());
            }
        }
        finally
        {
            // Clear the RijndaelManaged object.
            aesAlg?.Clear();
        }

        // Return the encrypted bytes from the memory stream.
        return str_outStr;
    }

Can any one suggest me how to resolve this ?