【问题标题】:Encrypt Persian Messages加密波斯消息
【发布时间】:2021-01-04 05:06:19
【问题描述】:

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

This is the picture of messenger's main screen

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

我的密码

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;
}

【问题讨论】:

    标签: php encryption aes


    【解决方案1】:

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

    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 still shows special signs as question mark

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 2022-01-28
      • 2021-04-21
      相关资源
      最近更新 更多