首页 > 解决方案 > 加密波斯消息

问题描述

我的新信使有问题。
我想加密用户消息。
如果他们输入波斯语,我无法加密。

这是Messenger主屏幕的图片

这些未定义的符号(如:�)是我的问题
我该如何处理?

我的加密代码

function encrypt($message){
    // Store a string into the variable which
// need to be Encrypted
    $simple_string = $message;

// Store the cipher method
    $ciphering = "AES-128-CTR";

// Use OpenSSl Encryption method
    $iv_length = openssl_cipher_iv_length($ciphering);
    $options = 0;

// Non-NULL Initialization Vector for encryption
    $encryption_iv = '1234567891011121';

// Store the encryption key
    $encryption_key = "SparkSocial";

// Use openssl_encrypt() function to encrypt the data
    $encryption = openssl_encrypt($simple_string, $ciphering,
        $encryption_key, $options, $encryption_iv);
    return $encryption;
}

function decrypt($code){
    // Store the cipher method
    $ciphering = "AES-128-CTR";

    // Non-NULL Initialization Vector for decryption
    $decryption_iv = '1234567891011121';

// Store the decryption key
    $decryption_key = "SparkSocial";

    $options = 0;

    $decryption=openssl_decrypt ($code, $ciphering,
        $decryption_key, $options, $decryption_iv);

    return $decryption;
}

标签: phpencryptionaes

解决方案


快速运行您的代码显示,没有问题。

function encrypt($message){
// Store a string into the variable which
// need to be Encrypted
    $simple_string = $message;

// Store the cipher method
    $ciphering = "AES-128-CTR";

// Use OpenSSl Encryption method
    $iv_length = openssl_cipher_iv_length($ciphering);
    $options = 0;

// Non-NULL Initialization Vector for encryption
    $encryption_iv = '1234567891011121';

// Store the encryption key
    $encryption_key = "SparkSocial";

// Use openssl_encrypt() function to encrypt the data
    $encryption = openssl_encrypt($simple_string, $ciphering,
        $encryption_key, $options, $encryption_iv);
    return $encryption;
}

function decrypt($code){
    // Store the cipher method
    $ciphering = "AES-128-CTR";

    // Non-NULL Initialization Vector for decryption
    $decryption_iv = '1234567891011121';

// Store the decryption key
    $decryption_key = "SparkSocial";

    $options = 0;

    $decryption=openssl_decrypt ($code, $ciphering,
        $decryption_key, $options, $decryption_iv);

    return $decryption;
}

$a = encrypt("الف");
$b = decrypt($a);
echo $b;

输出:

الف 

因此,如果没有更多信息,我建议您查看Charset UTF-8 仍然显示特殊符号作为问号


推荐阅读