利用openssl函数来加密数据,然后使用post方法将加密数据传递给服务器。
- // 加密数据
- $data = 'This is the data to be encrypted';
- $key = 'This is the secret key';
- $encrypted_data = openssl_encrypt($data, 'AES-128-ECB', $key);
- // 使用POST方法传递加密数据
- $url = 'http://www.ityuyan.com/receive_data.php';
- $data = array('encrypted_data' => $encrypted_data);
- $options = array(
- 'http' => array(
- 'header' => "Content-type: application/x-www-form-urlencodedrn",
- 'method' => 'POST',
- 'content' => http_build_query($data)
- )
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);