# [PATCH] openssl_pkcs7_encrypt to/from variable or file

- Thread: https://externals.io/message/5205
- Original archive: https://news-web.php.net/php.internals/5205
- Started by Richard Antony Burton on 2003-11-05T11:22:45+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #5205 — Richard Antony Burton — 2003-11-05T11:22:45+00:00

URL: https://externals.io/message/5205#5205

I find having to encrypt to and from a file quite a pain. I create a message
in PHP, save it to a temporary file, encrypt it to a second temporary file,
read this file, then mail the contents. If you are working with the message,
either before or after encryption, in PHP then this process clearly contains
more effort than it needs to. Also, writing the plain text message to disk
and then deleting it with the unlink, isn't all that secure.

This patch allows you to supply the message to encrypt as a string, and
allows you to get back the encrypted message as a string. Of course it is
still possible to use files if you prefer (by specifying files with the
"file://" prefix, as used by the certificate parameter).  It's fairly
simple, and should probably be applied to other functions in this extension
too. If people like it, I'd be happy to do the same to these functions.

As I see it there are three potential problems with this patch:
1) Changes default behaviour (people wanting to use files would need to add
"file://" to their filenames), so would be best added at a major version.
2) Encrypting a message from memory may not be binary safe (output to memory
will always be binary safe).
3) It's my first patch, so it may not be perfect. I'm happy to accept
criticism.

Richard.

---

## #5208 — Eric COLINET — 2003-11-05T11:57:20+00:00

URL: https://externals.io/message/5205#5208 · In reply to: #5205

Hi !

In the same series ..

I have no patch to provide but i've written two functions related to 
php_openssl:
         openssl_pubkey_export
         openssl_pubkey_export_to_file

That simply allow the export of public keys that seems to be not possible 
before.

I there is no special reason for that i can submit them (they are small 
modification of openssl_pkey_export & openssl_pkey_export_to_file)


Eric


At 12:22 05/11/2003, Richard Antony Burton wrote:
>I find having to encrypt to and from a file quite a pain. I create a message
>in PHP, save it to a temporary file, encrypt it to a second temporary file,
>read this file, then mail the contents. If you are working with the message,
>either before or after encryption, in PHP then this process clearly contains
>more effort than it needs to. Also, writing the plain text message to disk
>and then deleting it with the unlink, isn't all that secure.
>
>This patch allows you to supply the message to encrypt as a string, and
>allows you to get back the encrypted message as a string. Of course it is
>still possible to use files if you prefer (by specifying files with the
>"file://" prefix, as used by the certificate parameter).  It's fairly
>simple, and should probably be applied to other functions in this extension
>too. If people like it, I'd be happy to do the same to these functions.
>
>As I see it there are three potential problems with this patch:
>1) Changes default behaviour (people wanting to use files would need to add
>"file://" to their filenames), so would be best added at a major version.
>2) Encrypting a message from memory may not be binary safe (output to memory
>will always be binary safe).
>3) It's my first patch, so it may not be perfect. I'm happy to accept
>criticism.
>
>Richard.

---

## #5217 — Wez Furlong — 2003-11-05T14:31:28+00:00

URL: https://externals.io/message/5205#5217 · In reply to: #5208

I'm always open to patches; please send it as I plan to do some work on
openssl in the near future.

Thanks!

--Wez.

----- Original Message ----- 
From: "Eric COLINET" <e.colinet@laposte.net>
To: <internals@lists.php.net>
Cc: <wez@php.net>
Sent: Wednesday, November 05, 2003 12:57 PM
Subject: Re: [PHP-DEV] [PATCH] openssl_pkcs7_encrypt to/from variable or
file


> Hi !
>
> In the same series ..
>
> I have no patch to provide but i've written two functions related to
> php_openssl:
>          openssl_pubkey_export
>          openssl_pubkey_export_to_file
>
> That simply allow the export of public keys that seems to be not possible
> before.
>
> I there is no special reason for that i can submit them (they are small
> modification of openssl_pkey_export & openssl_pkey_export_to_file)
