I want to save an encrypted value in the database and while getting the value from database I want to decrypt and show the value in the UI. Here is the code I used
private string Decryptdata(string encryptpwd)
{
    string decryptpwd = string.Empty;
    UTF8Encoding encodepwd = new UTF8Encoding();
    Decoder Decode = encodepwd.GetDecoder();
    encryptpwd = encryptpwd.Replace(" ", "+");
    byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
    int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
    char[] decoded_char = new char[charCount];
    Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
    decryptpwd = new String(decoded_char);
    return decryptpwd;
}
But I'm getting error as Invalid length for a Base-64 char array. I'm using c#.net
encrypt function:
Encryptdata(string password) { 
       string strmsg = string.Empty; 
       byte[] encode = new byte[password.Length]; 
       encode = Encoding.UTF8.GetBytes(password); 
       strmsg = Convert.ToBase64String(encode); 
       return strmsg; 
}
 
     
    