Rare characters when decoding chain in Base64

2

Good, I've been trying for several days to pass a chain in base64 to something worthy, I explain that I've tried to see what solution I can give you.

First of all I use PHP, the string is encoded in C # with Convert.Tobase64String()

  • I pass the string "AAECAQcGqga5sgKsuwLTwwKZxwKixwIMS5EDogSRBv8HsgiCrQLSrgL+vAKhwgK8wwLKwwIA" by base64_decode()
  • I get a result like this "�����������K�������Ү��������"
  • Thought is so ASCII characters I perform the following procedure

    $a = base64_decode($base64);
    $b = array();
    foreach(str_split($a) as $c)
    $b[] = bindec(sprintf("%08b", ord($c)));
    
  • An array with numbers comes out but should correspond to an id in a list. Thing they do not.

    The code in C # I can not apply for confidentiality reasons, but what I can say is that the content is a Byte array.

        
    asked by Francisco Manuel Gonzalez Triv 02.06.2017 в 23:25
    source

    1 answer

    0

    I had this problem in PHP for some reason I did not erase those characters, modify the function to the following: Assuming your result is east:

    $var = "�����������K�������Ү��������";
    

    and we have this function:

    function desencriptar($valor_encriptado) {
              $utf8 = array(
                '/[áàâãªä]/u'   =>   'a',
                '/[ÁÀÂÃÄ]/u'    =>   'A',
                '/[ÍÌÎÏ]/u'     =>   'I',
                '/[íìîï]/u'     =>   'i',
                '/[éèêë]/u'     =>   'e',
                '/[ÉÈÊË]/u'     =>   'E',
                '/[óòôõºö]/u'   =>   'o',
                '/[ÓÒÔÕÖ]/u'    =>   'O',
                '/[úùûü]/u'     =>   'u',
                '/[ÚÙÛÜ]/u'     =>   'U',
                '/ç/'           =>   'c',
                '/Ç/'           =>   'C',
                '/ñ/'           =>   'n',
                '/Ñ/'           =>   'N',
                '/–/'           =>   '-', // UTF-8 hyphen to "normal" hyphen
                '/[’‘‹›‚]/u'    =>   ' ', // Literally a single quote
                '/[“”«»„]/u'    =>   ' ', // Double quote
                '/ /'           =>   ' ', // nonbreaking space (equiv. to 0x160)
            '/[^a-zA-Z0-9-+#=\/?\'\s]/' => ''
            );
            return preg_replace(array_keys($utf8), array_values($utf8), $valor_encriptado );     
        }
    

    We clean the variable

    var_dump(desencriptar($var));
    
        
    answered by 03.06.2017 в 00:09