php - 加密波斯消息
问题描述
我的新信使有问题。
我想加密用户消息。
如果他们输入波斯语,我无法加密。
这些未定义的符号(如:�)是我的问题
我该如何处理?
我的加密代码
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;
}
解决方案
快速运行您的代码显示,没有问题。
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 仍然显示特殊符号作为问号
推荐阅读
- php - laravel中如何查询jsonb列
- flutter - 单击“下一页”按钮时颤动分页
- laravel-livewire - 为什么清除过滤器后我在日期选择器上看到日期标签?
- php - 如何在 woocommerce 的帐户详细信息页面中显示自定义用户注册详细信息
- azure-functions - Dotnet Core Azure 函数(隔离进程)如何为每个环境加载 appsettings.json
- python - Python pandas 中的深度嵌套 JSON 规范化
- node.js - 如何优化 PSQL 的 TypeORM 更新查询的性能
- android - Android 应用拒绝说“不遵守权限政策”
- litho - 即使加载了新部分,FbLitho 也会在 RecyclerCollectionComponent 中重复视图
- powerbi - 我们可以通过调用 Power BI 服务/工作区的导出功能来导出嵌入式 Power BI 报表的 PDF 和 PPT