PublicEncrypte.php
934 Bytes
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
<?php
include_once 'PinBlock.php';
function EncryptedPin($sPin, $sCardNo ,$sPubKeyURL)
{
$sPubKeyURL = trim(dirname(__FILE__) . '/../' . SDK_ENCRYPT_CERT_PATH," ");
$fp = fopen($sPubKeyURL, "r");
if ($fp != NULL)
{
$sCrt = fread($fp, 8192);
fclose($fp);
}
$sPubCrt = openssl_x509_read($sCrt);
if ($sPubCrt === FALSE)
{
print("openssl_x509_read in false!");
return (-1);
}
$sPubKey = openssl_x509_parse($sPubCrt);
$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)
{
$sBase64EncodeOutData = base64_encode($sOutData);
return $sBase64EncodeOutData;
}
else
{
print("openssl_public_encrypt Error !");
return (-1);
}
}
?>