Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asymmetric encryption with mcrypt or other php library

Status
Not open for further replies.

leehinkleman

Programmer
Feb 14, 2002
83
NZ
Can PHP encrypt a string using the public key, of a public and private key set?
Alternatively, how can I hide the private $key if mcrypt is used, as in
$enc=mcrypt_encrypt($c_alg,$key,$str,MCRYPT_MODE_CBC,$iv);
and if $key has to be readable in the php script?
Thanks for your help.
 
According to the mcrypt page, mcrypt supports OpenGPG encryption since version 2.6.0. However, PHP does not yet support PKI encryption -- it looks like PHP 5.0 might.

You can invoke PKI encryption software externally. Let me know if this link was helpful:
Want the best answers? Ask the best questions: TANSTAAFL!!
 
Thanks sleipner214.
I read Julie Meloni's tutorial, made a new set of public and private keys, using the ElGamir option and 1024 bits.
Julie said, I think, to ftp my public key as a text file to my webhost, so I tried
gpg --list-keys and found public key 943ED4C3.
I then thought I needed to output that file to a text file, so I tried
gpg --export 943ED4C3 --armor --output k0.txt
but that just resulted in a 1/2 screenful of binary symbolism, with no k0.txt file written, so I ftp'd the entire pubring.gpg file to my main directory, which my webhost has set up as /I've since learned that my webhost does not have GNUPG installed, but they've offered to install it. My webhost also does not allow telnet nor SSH, so I've asked them if they can add my public key to PHP's keyring.
Can you please tell me the gpg command I should have used to output my public key to a file for ftp to my webhost?
Thanks again.
 
I learned that my --export command was out-of-sequence, and successfully exported the public key with the command,
gpg --armor --output taupokey.asc --export 90AB7164

My webhost tells me they've imported the key for user PHP which, I think is 'nobody', but now the system call, as in Julie Meloni's tutorial isn't working, and the putenv() argument may be incorrect:
putenv("GNUPGHOME=/home/
or the system call:
system("/usr/bin/gpg --encrypt -ao $crypted -r 90AB7164 $plainTxt");
may be incorrect, but a perl `whereis gpg` command did find gpg in /usr/bin/gpg

The system call to --encrypt is failing.
Is the error obvious?
Thanks again.
 
You haven't asked a question about putenv() that I can see. PHP's putenv() function sets an environment variable. You appear to be invoking it correctly. The function is documented here:
Whether or not your use of it will do any good depends on whether the value you're assigning the variable is appropriate. The appropriateness of the value of the variable is a question pertinent to your particular installation of OpenGPG, not to PHP.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top