‘some@pgp_user.com<\/a>‘;
$command = “$gpg $switches -e -r $recipient”;<\/p>\n \/\/ take in the plain text data
$message = $_POST[‘plain’];<\/p>\n
$descriptorspec = array(
0 => array(“pipe”, “r”), \/\/ stdin is a pipe that the child will read from
1 => array(“pipe”, “w”), \/\/ stdout is a pipe that the child will write to
2 => array(“file”, “\/tmp\/error-output.txt”, “a”) \/\/ stderr is a file to write to
);<\/p>\n
putenv(“GNUPGHOME=\/var\/www\/.gnupg”);
$process = proc_open($command, $descriptorspec, $pipes);
if (is_resource($process)) {
\/\/ $pipes now looks like this:
\/\/ 0 => writeable handle connected to child stdin
\/\/ 1 => readable handle connected to child stdout
\/\/ Any error output will be appended to \/tmp\/error-output.txt<\/p>\n
fwrite($pipes[0], $message);
fclose($pipes[0]);<\/p>\n
while (!feof($pipes[1])) {
$encrypted_message .= fgets($pipes[1], 1024);
}
fclose($pipes[1]);<\/p>\n
\/\/ It is important that you close any pipes before calling
\/\/ proc_close in order to avoid a deadlock
$return_value = proc_close($process);
}<\/p>\n
$_POST[‘crypted’] = $encrypted_message;
?><\/p>\n
<!DOCTYPE HTML PUBLIC “-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN” “http:\/\/www.w3.org\/TR\/html4\/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text\/html; charset=iso-8859-1″>
<title>GPG Proof of concept page.<\/title>
<\/head><\/p>\n
<body>
<form name=”form1″ method=”POST” action=”gpg.php”>
<p>Plaintext Data:<\/p>
<p>
<textarea name=”plain” cols=”80″ rows=”15″ id=”plain”><?php echo $_POST[‘plain’]; ?><\/textarea>
<\/p>
<p>
<input type=”submit” name=”Submit” value=”Encrypt”>
<\/p>
<p>Encrypted Data (will always appear, even if blank input): <\/p>
<p>
<textarea name=”crypted_display” cols=”80″ rows=”15″ id=”crypted_display”><?php echo $_POST[‘crypted’]; ?><\/textarea>
<\/p>
<input name=”crypted” type=”hidden” id=”crypted”>
<\/form>
<\/body>
<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"
Ah, encryption. I recently had to use GPG\/PGP to encrypt some data to store in a database with PHP. On the way to doing that I wound up doing a small proof of concept page. The code is shown below. In essence, the steps are: Pull the clear text from the form at $_POST[‘plain’] Encrypt […]<\/p>\n","protected":false},"author":3,"featured_media":56223,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[278],"tags":[],"_links":{"self":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts\/2213"}],"collection":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/comments?post=2213"}],"version-history":[{"count":0,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts\/2213\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/media\/56223"}],"wp:attachment":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/media?parent=2213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/categories?post=2213"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/tags?post=2213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}