Skip to content

Instantly share code, notes, and snippets.

@sh1n0b1
Created September 30, 2015 00:54
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 sh1n0b1/35450bd07b7cbdfa5482 to your computer and use it in GitHub Desktop.
Save sh1n0b1/35450bd07b7cbdfa5482 to your computer and use it in GitHub Desktop.
Decrypt strings encrypted by PKCS12 keys
<?php
$p12cert = array();
$file = '[PATH]]';
$c = file_get_contents($file);
if (openssl_pkcs12_read($c, $p12cert, '[REDACTED]') )
{
$pkey = $p12cert['pkey']; //private key
$cert = $p12cert['cert']; //public key
//decrypt the encrypted parameter value
$crypted = $argv[1];
if(openssl_private_decrypt(base64_decode($crypted), $decrypted, $pkey)){
echo $decrypted;
}else{
echo 'failed to decrypt';
}
}
else
{
echo 'Failed read p12 file';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment