Forum Moderators: coopster
When I use something like this from PHP :shell_exec("echo $argv[1] ¦ $gpg -e -r $recipient")
I capture it into a variable. The problem is I want to store it in a database and decrypt or decrypt in some other way.
I can't though because the data is just random junk as it should be......but there is no header or footer like:
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.2.1 (GNU/Linux)
jibberish
-----END PGP MESSAGE-----
Does anyone know how to make this work nicely or is there a special switch in GPG.
Right now if you run the encrypted data through GPG I get this error: gpg: no valid OpenPGP data found.
Of course if I wrote it to a file then it works because it has the fancy header/footer.
Anyone know how to fix this?
The problem is that when you take that data and try to decrypt it, GPG doesn't recognize it.
Basically I guess I want to know how you can encrypt data and then decrypt it without ever putting it into a file. Sounds funny, but I'm having issues when not using it with files.
I think the reason is that with files it has the header and footer and I think that is the only way GPG knows what to do with it.
Does that explain it better?
Well this is different and even if that was using gpg it wouldn't help. Of course I know what the unencrypted string is.
The issue is that once encrypted into a variable I cannot decrypt it. GPG says it doesn't see any valid data....I don't know why or how to make it work.
If I encrypt a file then I can decrypt it, but when not using files I just can't figure out how to make it work :(
Anyone here experienced with PHP and GPG?
The issue is that once encrypted into a variable I cannot decrypt it.
That's exactly my point, stidj. Why do you even have a need to *decrypt* it in your script? You just encrypted the variable, so you still have the original value in memory somewhere, why do you need to decrypt it?
I'm not trying to frustrate you, by the way, I'm just trying to help clarify your thoughts here so myself and others can understand what you are trying to do. It is still very unclear. Thanks for your patience.
Sorry if my last comment appeared to be in frustration, it really wasn't. I was trying to clarify more too.
I don't want to decrypt the variable in that script. I want to decrypt it on another machine.
The idea is that later I should be able to decrypt it somewhere else, of course if GPG won't recognize the data as being valid I can't decrypt it anywhere.
Is that clear? Anyone feel free to ask away if I am not being clear......whoever can help solve this first will get the best cyber beer :)
shell_exec("echo $argv[1] ¦ $gpg -e -r $recipient")
Is this "like" what you're using or are you using that line exactly?
PHP will not recognize array references inside double quotes. So you may be encrypting a blank variable, that's why it doesn't recognize it.
try:
shell_exec("echo " . $argv[1] . " ¦ $gpg -e -r $recipient") I could be completely off base here, but it's worth a shot.
Thanks
If that doesn't work I think I'll go the route of encrypting to a file because I know that always works fine with decryption and then reading the contents of the file into the variable.
I think the issue is that by not sending it to a file all you get back is encrypted data but the header and footer part you normally see in an encrypted file is not there.
I could be wrong and if I am someone tell me exactly why and how to make this work :)
I promise a round of beer for all!
The way to fix it is to use all of these switches when executing gpg ( in addition to the obvious -e for encryption and -r for recipient)
--always-trust --no-secmem-warning -e -a --batch -t
Just for putting up with me here is big round of cyber beer and hopefully this thread ends up helping someone who will inevitably have the same issue one day.
Cheers
So I was right, you will likely have issues if you do not use the mentioned switches :)
I've implemented this before, with varying degrees of success.
BTW, I'm just adding to this thread so that others reading this will understand what the differences are between the original command and the one that worked. :)