人人商城

PublicEncrypte.php 858B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. function EncryptedPin($sPin, $sCardNo ,$sPubKeyURL)
  3. {
  4. global $log;
  5. $sPubKeyURL = trim(SDK_ENCRYPT_CERT_PATH," ");
  6. $fp = fopen($sPubKeyURL, "r");
  7. if ($fp != NULL)
  8. {
  9. $sCrt = fread($fp, 8192);
  10. fclose($fp);
  11. }
  12. $sPubCrt = openssl_x509_read($sCrt);
  13. if ($sPubCrt === FALSE)
  14. {
  15. print("openssl_x509_read in false!");
  16. return (-1);
  17. }
  18. $sPubKey = openssl_x509_parse($sPubCrt);
  19. $sInput = Pin2PinBlockWithCardNO($sPin, $sCardNo);
  20. if ($sInput == 1)
  21. {
  22. print("Pin2PinBlockWithCardNO Error ! : " . $sInput);
  23. return (1);
  24. }
  25. $iRet = openssl_public_encrypt($sInput, $sOutData, $sCrt, OPENSSL_PKCS1_PADDING);
  26. if ($iRet === TRUE)
  27. {
  28. $sBase64EncodeOutData = base64_encode($sOutData);
  29. return $sBase64EncodeOutData;
  30. }
  31. else
  32. {
  33. print("openssl_public_encrypt Error !");
  34. return (-1);
  35. }
  36. }
  37. ?>