When trying to perform these functions (with salt being a string of 32 characters and passing a string of a variable number of characters):
public static string encodePassword(string salt, string pass)
{
pass = mod4(pass); /// Necesitamos que la cadena sea multiplo de 4
pass = Convert.ToBase64String(Encoding.UTF8.GetBytes(pass));
pass += salt;
pass = mod4(pass);
pass = Convert.ToBase64String(Encoding.UTF8.GetBytes(pass));
return pass;
}
private static string mod4(string a)
{
int mod4 = a.Length % 4;
if (mod4 > 0)
{
a += new string('=', 4 - mod4);
}
return a;
}
Always gives the error: System.FormatException: Invalid length for a Base-64 char array or string.
What could be causing the problem?
The mod4 function has been extracted from this question.