IcbcSignature.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. include_once 'IcbcConstants.php';
  3. include_once 'IcbcCa.php';
  4. include_once 'RSA.php';
  5. class IcbcSignature{
  6. public static function sign($strToSign, $signType, $privateKey, $charset,$password){
  7. if (IcbcConstants::$SIGN_TYPE_CA == $signType){
  8. return IcbcCa::sign($strToSign,$privateKey,$password);
  9. }elseif (IcbcConstants::$SIGN_TYPE_RSA == $signType) {
  10. return RSA::sign($strToSign,$privateKey,IcbcConstants::$SIGN_SHA1RSA_ALGORITHMS);
  11. }elseif (IcbcConstants::$SIGN_TYPE_RSA2 == $signType) {
  12. return RSA::sign($strToSign,$privateKey,IcbcConstants::$SIGN_SHA256RSA_ALGORITHMS);
  13. }else{
  14. throw new Exception("Only support CA\RSA signature!");
  15. }
  16. }
  17. public static function verify($strToSign, $signType, $publicKey, $charset,$signedStr,$password){
  18. if (IcbcConstants::$SIGN_TYPE_CA == $signType){
  19. return IcbcCa::verify($strToSign,$publicKey,$password);
  20. }elseif (IcbcConstants::$SIGN_TYPE_RSA == $signType) {
  21. return RSA::verify($strToSign,$signedStr,$publicKey,IcbcConstants::$SIGN_SHA1RSA_ALGORITHMS);
  22. }elseif (IcbcConstants::$SIGN_TYPE_RSA2 == $signType) {
  23. return RSA::verify($strToSign,$signedStr,$publicKey,IcbcConstants::$SIGN_SHA256RSA_ALGORITHMS);
  24. }else{
  25. throw new Exception("Only support CA or RSA signature verify!");
  26. }
  27. }
  28. }
  29. ?>