php - openssl_decrypt 是否在 Ubuntu 上运行的 PHP 上使用任何网络调用?
问题描述
我正在使用 PHP 函数 openssl_encrypt 来加密聊天消息。当我可以访问 Internet 时它工作正常,但是当我在未连接到 Internet 的 Ubuntu 服务器上运行相同的代码时,它很慢。
谁能指出我解决此问题的正确方向?openssl_decrypt 是否在 Ubuntu 上运行的 PHP 上使用任何网络调用?
加密消息:
$inp_text = "SOME TEXT THAT WILL BE ENCRYPTED";
$get_current_channel_encryption_key = "SOME ENCRYPTION KEY";
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($inp_text, $cipher, $get_current_channel_encryption_key, $options=OPENSSL_RAW_DATA, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, $get_current_channel_encryption_key, $as_binary=true);
$ciphertext = base64_encode( $iv.$hmac.$ciphertext_raw );
解密消息:
$get_message_text = "SOME ENCRYPTED MESSAGE";
$get_current_channel_encryption_key = "SOME ENCRYPTION KEY";
$c = base64_decode($get_message_text);
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = substr($c, 0, $ivlen);
$hmac = substr($c, $ivlen, $sha2len=32);
$ciphertext_raw = substr($c, $ivlen+$sha2len);
$original_plaintext = openssl_decrypt($ciphertext_raw, $cipher, $get_current_channel_encryption_key, $options=OPENSSL_RAW_DATA, $iv);
$calcmac = hash_hmac('sha256', $ciphertext_raw, $get_current_channel_encryption_key, $as_binary=true);
if (hash_equals($hmac, $calcmac))//PHP 5.6+ timing attack safe comparison
{
$get_message_text = "$original_plaintext";
}
解决方案
推荐阅读
- memory - Chisel - 内存初始化
- java - tomcat启动时的ContextLoaderListener异常
- python-3.x - Python Dash数据表:行选择不起作用
- laravel-nova - Laravel Nova 搜索字幕
- regex - 正则表达式 - 如何在不同的行中交换两个表达式?
- excel - VBA EXCEL .AutoFilter 逻辑
- laravel - 如何在刀片文件中使用 vue 组件,如单选按钮?
- swiftui - 如何在不中断删除的情况下在 SwiftUI 中实现 TextField 列表
- python - 设置单个轴对象(XAxis 或 YAxis)的限制
- javascript - 适用于 repl.it 不适用 freeCodeCamp - JavaScript 算法和数据结构项目:罗马数字转换器