-1

Why when converting string to byte[] using Convert.FromBase64String(...) i can't put two same characters?

For example I have

 class User
{
    public string Login { get; set; }
    public byte[] Password { get; set; }

}
class Program
{
    static void Main(string[] args)
    {
        var login = Console.ReadLine();
        var password = Console.ReadLine();
        var bytePass = Convert.FromBase64String(password);

        var user = new User() { Login = login, Password = bytePass };

    }
}

When I put as password string with two same characters ("testt" for example) it throw exception

System.FormatException: „The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.”

What I should to do if I want convert string which multiple same characters to byte[]? Is it even possible?

mikeyMike
  • 21
  • 4

1 Answers1

1

The string testt is not a Base64-encoded string. The length of a Base64 string must be a multiple of four.

To convert a regular string to a sequence of bytes, use the Encoding.GetBytes method.

Richard Deeming
  • 29,830
  • 10
  • 79
  • 151