PublicEncrypte.php
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
include_once 'PinBlock.php';
function EncryptedPin($sPin, $sCardNo ,$sPubKeyURL)
{
global $log;
$sPubKeyURL = trim(dirname(__FILE__) . '/../' . SDK_ENCRYPT_CERT_PATH," ");
$fp = fopen($sPubKeyURL, "r");
if ($fp != NULL)
{
$sCrt = fread($fp, 8192);
// $log->LogInfo("fread PubKeyURL : " . $sCrt);
fclose($fp);
}
$sPubCrt = openssl_x509_read($sCrt);
if ($sPubCrt === FALSE)
{
print("openssl_x509_read in false!");
return (-1);
}
// $log->LogInfo($sPubCrt);
// $sPubKeyId = openssl_x509_parse($sCrt);
// $log->LogInfo($sPubKeyId);
$sPubKey = openssl_x509_parse($sPubCrt);
// $log->LogInfo($sPubKey);
// openssl_x509_free($sPubCrt);
// print_r(openssl_get_publickey($sCrt));
$sInput = Pin2PinBlockWithCardNO($sPin, $sCardNo);
if ($sInput == 1)
{
print("Pin2PinBlockWithCardNO Error ! : " . $sInput);
return (1);
}
$iRet = openssl_public_encrypt($sInput, $sOutData, $sCrt, OPENSSL_PKCS1_PADDING);
if ($iRet === TRUE)
{
// $log->LogInfo($sOutData);
$sBase64EncodeOutData = base64_encode($sOutData);
//print("PayerPin : " . $sBase64EncodeOutData);
return $sBase64EncodeOutData;
}
else
{
print("openssl_public_encrypt Error !");
return (-1);
}
}
?>