Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What i make wrong?

PHP
$massiv = [10,202,3];
$massiv = array_map("chr",$massiv);
$rezult= implode('',$massiv);
$temp = base64_encode($rezult);
echo $temp

rezult --> CsoD


C#
List<int> lst = new List<int>(){10,202,3};
       var rez = string.Join("",lst.Select(x => Convert.ToChar(x)).ToList());

      var bytes = System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(rez));

rezult --> Cj8D
Posted

1 solution

The problem is in System.Text.Encoding.ASCII.GetBytes usage over a not ASCII value, namely 202 becomes 63.
It is worth nothing you don't need all that stuff.
C#
string s = System.Convert.ToBase64String(new byte [] { 10, 202, 3 });

is just enough.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900