Php 如何使用外来字符执行MD5?

Php 如何使用外来字符执行MD5?,php,mysql,unity3d,md5,Php,Mysql,Unity3d,Md5,所以我在手机游戏中使用unity engine制作自定义高分板 我设置了我的mysql数据库,并从商店购买了highscore资产,它可以工作,但只有英文用户名。所以基本上它会将用户名、分数发送到.php脚本 但我希望该脚本也可以接收韩文字符作为用户的昵称。我的用户将使用韩语字符作为昵称,而不仅仅是英语字符 我怎样才能做到这一点 这里是代码 ------------------(unity侧的Highscore.cs) string GetHash(string usedString){ //

所以我在手机游戏中使用unity engine制作自定义高分板

我设置了我的mysql数据库,并从商店购买了highscore资产,它可以工作,但只有英文用户名。所以基本上它会将用户名、分数发送到.php脚本

但我希望该脚本也可以接收韩文字符作为用户的昵称。我的用户将使用韩语字符作为昵称,而不仅仅是英语字符

我怎样才能做到这一点

这里是代码

------------------(unity侧的Highscore.cs)

string GetHash(string usedString){ //Create a Hash to send to server
    MD5 md5 = MD5.Create();
    byte[] bytes = Encoding.ASCII.GetBytes(usedString+secretKey);
    byte[] hash = md5.ComputeHash(bytes);

    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < hash.Length; i++){
        sb.Append(hash[i].ToString("x2"));
    }
    return sb.ToString();
}
当我输入韩文字符并发送时,控制台结果在上面的代码中显示“安全失败”

如用户之前所述,如果使用的ascii字符不足(韩语、日语等的情况),则使用的编码是错误的。您应该使用Encoding.UTF8.GetBytes而不是Encoding.ASCII.GetBytes,请查看示例函数GetMd5Hash。如果运行ASCII md5,将生成不同的md5

“salt”是您正在使用的密钥$PHP中的secretKey和C#中的secretKey。如果你不知道salt是什么,你应该读一点关于安全的知识,因为如果你不知道,你会认为你创建了一个安全的(r)系统,而你还没有


希望有帮助。

在尝试散列之前,您可能应该对插入的值进行编码?
byte[]bytes=Encoding.ASCII.GetBytes(usedString+secretKey)。您的C#代码使用了错误的编码。也许您应该将分数或等效值与名称和salt一起散列,创建一个正确的校验和?如果您只对名称进行哈希运算,则用户可以嗅探名称/哈希并使用不同的分数集发布。@OfirBaruch如何操作?@Phylogenesis那么我应该如何修改?谢谢!!!更改为UTF8。“盐”是我定制的秘钥,我设定的。
string GetHash(string usedString){ //Create a Hash to send to server
    MD5 md5 = MD5.Create();
    byte[] bytes = Encoding.ASCII.GetBytes(usedString+secretKey);
    byte[] hash = md5.ComputeHash(bytes);

    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < hash.Length; i++){
        sb.Append(hash[i].ToString("x2"));
    }
    return sb.ToString();
<?php
include('ServerConnect.php');
$connection = Connect();//Attempt to Connect to MYSQL Server & DataBase

//Get variables from unity
$name = $_POST['name'];
$date = strtotime(date("Y-m-d"));
$tables = $_POST['tables'];
//Security Check
$hash = $_POST['hash'];
if(CheckKey($hash,$name) == 'fail'){ //Check if hash is valid
    echo 'Security Failure'; exit;
function CheckKey($hash,$name){  //Check weather Md5 hash matches
    global $secretKey; 
    $checkHash = md5($name.$secretKey);
    if(strcmp($checkHash,$hash) == 0){
        return 'pass'; //hash matches
    }else{
        return 'fail'; //hash failed
    }