Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenwaite/4f9ec6ef88be25d1889869043ff2988f to your computer and use it in GitHub Desktop.
Save stephenwaite/4f9ec6ef88be25d1889869043ff2988f to your computer and use it in GitHub Desktop.
php de-crypto docs
<?php
$_GET['site'] = 'default';
$ignoreAuth = true;
require_once __DIR__ . '/vendor/autoload.php';
require_once("interface/globals.php");
use OpenEMR\Common\Crypto\CryptoGen;
$crypto = new CryptoGen();
$dir = new RecursiveDirectoryIterator(__DIR__ . "/sites/default/documents/", FilesystemIterator::SKIP_DOTS);
$subdirs = new RecursiveIteratorIterator($dir);
foreach($subdirs as $filename_path) {
$parent_dir = $subdirs->getSubPath();
// echo $filename_path, PHP_EOL;
// documents are stored under numeric pid in documents folder
if (is_numeric($parent_dir)) {
$filename = basename($filename_path);
// echo $filename, PHP_EOL;
$new_name = $filename_path . "-decrypted";
//echo $new_name;
if (!$fp = fopen($new_name, 'w')) {
echo "Cannot write file ($new_name)";
exit;
}
$encrypted_file_contents = file_get_contents($filename_path);
//echo $encrypted_file_contents, PHP_EOL;
$file_contents = $crypto->decryptStandard($encrypted_file_contents, '', 'database');
if (fwrite($fp, $file_contents) === FALSE) {
echo "Cannot write to file ($new_name)";
exit;
}
echo "Success, wrote ($file_contents) to file ($new_name)";
fclose($fp);
}
}
@sovannapp
Copy link

hello @jfischburg-lifemesh how put this code to? i was created new php but it not work. please tell me how to do with this code? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment