Solution to multipart encryption and decryption of mail body

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.