Created
February 1, 2016 09:33
-
-
Save channainfo/9ffc9578936447e9740e to your computer and use it in GitHub Desktop.
Smart luy payment gateway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL); | |
$public_key_file = "book_me_bus_public.key" ; | |
$private_key_file = "book_me_bus_private.key" ; | |
function better_echo($var, $title = "") { | |
if($title) | |
echo "\n ------------------------{$title}"; | |
echo "\n{$var}\n"; | |
} | |
function blog64_line($datas) { | |
$i = 0; | |
$lines = []; | |
while(true) { | |
$chunk = substr($datas, $i * 64, 64); | |
$lines[] = $chunk; | |
if(strlen($chunk) < 64) | |
break; | |
$i = $i + 1; | |
} | |
return implode($lines, "\n"); | |
} | |
$public_key_content = file_get_contents($public_key_file); | |
$public_key_content = blog64_line($public_key_content); | |
$public_key = "-----BEGIN PUBLIC KEY-----\n{$public_key_content}\n-----END PUBLIC KEY-----"; | |
better_echo($public_key, "public key: "); | |
$message = "hello|world|10"; | |
if(!openssl_public_encrypt($message, $encrypted, $public_key)) { | |
die("error encryption"); | |
} | |
better_echo($encrypted, "encrypted data"); | |
$private_key_content = file_get_contents(private_key_content); | |
$private_key_content = blog64_line($private_key_content); | |
$private_key = "-----BEGIN PRIVATE KEY-----\n{$private_key_content}\n-----END PRIVATE KEY-----"; | |
better_echo($private_key, "private key: "); | |
if (!openssl_private_decrypt($encrypted, $decrypted, $private_key)) | |
die('Failed to decrypt data'); | |
better_echo($decrypted, "message decrypt:"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment