How to encrypt and decrypt the mail body in segments -------- php source code ----------- PHPcode $ mailcont = & quot; mail body ......... More than 1024 bytes ......... Email body & quot; $ crtpath = & quot;/u how to encrypt and decrypt the email body in segments
-------- Php source code -------------
PHP code
$ Mailcont = "email body ......... More than 1024 bytes ......... Email body "; $ 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); // Parse the public key from the certificate $ keyData = openssl_pkey_get_details ($ pubKey); $ blocks = str_split ($ mailcont, 1000); foreach ($ blocks as $ block) {// public key encryption if (! Openssl_public_encrypt ($ block, $ chrtext, $ keyData ['key']) {echo"
". Openssl_error_string ()."
";}$ Chrtext. = $ chrtext;} echo" chrtext -- >>> $ chrtext
"; $ 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
";
----------------- Error response ----------------
Error: 0906D06C: PEM routines: PEM_read_bio: no start line
Error: 0406D06E: rsa routines: RSA_padding_add_PKCS1_type_2: data too large for key size
Chrtext --> uncle ?? After 50? Oxygen (due to T? r'um? DcyCont -->
--------------------
The certificate and private key are absolutely correct, but the openssl_public_encrypt () function does not seem to support circular encryption? Solution !!!
------ Solution --------------------
The file is too large. encrypt the content in part
------ Solution --------------------
Str_split ($ mailcont, 100); you may have split the Chinese string!
------ Solution --------------------
Encryption is a big deal, but other email service providers will not solve your password. Struggling. Add or not