The problem lies with whatever is calling "encode". My guess is that you are doing ToString on something just to make the code compile. For example;
string password = "123456";
var toEncode = password.ToArray();
string encoded = encode(toEncode);
If you're getting a char array from somewhere (I don't know where, I can't access your code) then the above won't compile. My guess is that in order to make it compile you have done something like this
string password = "123456";
var toEncode = password.ToArray().ToString();
string encoded = encode(toEncode);
...and that will give you your problem. You need to track all code that calls your function and see if there is any chance you are trying to encode a char array that has been converted ToString.