Need Help : Security unity + php

hi i using unity+php+sql to saveload data
and i need security thing
i get a function as

using UnityEngine;
using System;
using System.Collections;
using System.Text;
using System.Security.Cryptography;

public class convertAES64 : MonoBehaviour
{
    public static string Enkrip (string stringToEn)
    {
        byte[] keyArray = UTF8Encoding.UTF8.GetBytes ("12345678901234567890123456789012");

        byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes (stringToEn);
        RijndaelManaged rDel = new RijndaelManaged ();
        rDel.Key = keyArray;
        rDel.Mode = CipherMode.ECB;
        rDel.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = rDel.CreateEncryptor ();
        byte[] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length);
        return Convert.ToBase64String (resultArray, 0, resultArray.Length);
    }

    public static string Dekrip (string stringToDe)
    {
        byte[] keyArray = UTF8Encoding.UTF8.GetBytes ("12345678901234567890123456789012");
        byte[] toEncryptArray = Convert.FromBase64String (stringToDe);
        RijndaelManaged rDel = new RijndaelManaged ();
        rDel.Key = keyArray;
        rDel.Mode = CipherMode.ECB;
        rDel.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = rDel.CreateDecryptor ();
        byte[] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length);
        return UTF8Encoding.UTF8.GetString (resultArray);
    }

}

then in PHP im using :

class Aes{
   
    protected $key = '';
   
    public function __construct($key)
    {
        $this -> key = str_pad($key, 32, "\0", STR_PAD_RIGHT);
    }

    public function encrypt($str)
    {
         $block = mcrypt_get_block_size('rijndael_256', 'ecb');
         $pad = $block - (strlen($str) % $block);
         $str .= str_repeat(chr($pad), $pad);
         return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this -> key, $str, MCRYPT_MODE_ECB));
    }

    public function decrypt($str)
    {
         $str = base64_decode($str);
         $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this -> key, $str, MCRYPT_MODE_ECB);
         $block = mcrypt_get_block_size('rijndael_256', 'ecb');
         $pad = ord($str[($len = strlen($str)) - 1]);
         $len = strlen($str);
         $pad = ord($str[$len-1]);
         return substr($str, 0, strlen($str) - $pad);
    }

}

but result not same, anyone can help me?,
whats wrong in my csharp?
or anyone can help to convert my php function to csharp?

thanks :slight_smile:

To understand where mistake located, try to call Enkrip() and Dekrip() with result, to check it without php :wink:

solved, ive found another c# and php script synced.
Decrypt PHP encrypted string in C# - Stack Overflow
:wink: