Difference in PHP encryption from iOS and .NET

后端 未结 2 1193
春和景丽
春和景丽 2021-01-07 14:16

I have an issue when communicating encrypted between iOS and PHP. I have an app that encrypts a string and sends it to a PHP server that decrypts it. That part works just fi

2条回答
  •  萌比男神i
    2021-01-07 14:36

    After long test's I think this encrypt method will be right for tests:

    function mc_encrypt($str = "Affe", $key = "12345678901234567890123456789012")
    {
        $str = "Affe";
      $block = mcrypt_get_block_size('rijndael-256', 'cbc');
        $pad = $block - (strlen($str) % $block);
        $str .= str_repeat(chr($pad), $pad);
    
        $encoded =  base64_encode(mcrypt_encrypt('rijndael-256', $key, $str, 'cbc',$key));
        file_put_contents("test.txt",$encoded);
        return $encoded;
    }
    

    I got this on iOS: v+cB4woDYANTozUbOgxJ4rWKb59EfLf6NkRE/Ee0kYY= But if I try to decrypt (see above), I got (null)

    On the Other if I encrypt on iOS, I got this one: UUfn34iyNlSK40VaehloaQ==

    definitely to short (or the other is to long)...searching again for errors.

提交回复
热议问题