Heim >Backend-Entwicklung >PHP-Tutorial >怎样对邮件正文分段加密及解密解决思路
怎样对邮件正文分段加密及解密
--------php 源码-------------
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$mailcont = "邮件正文………超过1024字节………邮件正文"; $crtpath = "/usr/nc-home/webpost/mailbox/d00/1/y/u/yushuai.niu/.user/certkey/wxd.crt"; exec("chmod 777 {$crtpath}"); $fp = fopen($crtpath, "r"); $crt = fread($fp, 8192); fclose($fp); $pubKey = openssl_get_publickey($crt); //从证书中解析公钥 $keyData = openssl_pkey_get_details($pubKey); $blocks = str_split($mailcont, 1000); foreach ($blocks as $block) { //公钥加密 if (!openssl_public_encrypt($block, $chrtext, $keyData['key'])) { echo "<br>" . openssl_error_string() . "<br>"; } $chrtext .= $chrtext; } echo "chrtext-->>>$chrtext<br>"; $keypath = "/usr/nc-home/webpost/mailbox/d00/1/y/u/yushuai.niu/.user/secretkey/wxd.key"; exec("chmod 777 {$keypath}"); $fp = fopen($keypath, "r"); $key = fread($fp, 8192); fclose($fp); $cipher = openssl_pkey_get_private($key); openssl_private_decrypt($chrtext, $dcyCont, $cipher); echo "dcyCont-->>>$dcyCont<br>";