扩展 8003 指令
This commit is contained in:
@@ -91,6 +91,9 @@ public class SydApiException extends RuntimeException{
|
||||
msg = "证书删除错误";
|
||||
break;
|
||||
|
||||
case 0xC101 :
|
||||
msg = "证书识别异常";
|
||||
break;
|
||||
default:
|
||||
msg = "未定义的错误";
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.sunyard.util;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.constant.CertUsage;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import sun.misc.BASE64Encoder;
|
||||
@@ -78,7 +79,7 @@ public class CertUtil {
|
||||
* @param cert 证书 base64 字符
|
||||
* @return true 国密, false 非国密
|
||||
*/
|
||||
public static boolean isSM2Cert(String cert) throws CertificateException, NoSuchProviderException {
|
||||
public static boolean isSM2Cert(String cert) {
|
||||
String pemCert;
|
||||
if(cert.contains("-----BEGIN CERTIFICATE-----")){
|
||||
pemCert =cert;
|
||||
@@ -87,7 +88,12 @@ public class CertUtil {
|
||||
String end_cert = "\n-----END CERTIFICATE-----";
|
||||
pemCert = cert_begin + cert + end_cert;
|
||||
}
|
||||
X509Certificate certificate = convertToX509Cert(pemCert);
|
||||
X509Certificate certificate = null;
|
||||
try {
|
||||
certificate = convertToX509Cert(pemCert);
|
||||
} catch (Exception e) {
|
||||
throw new SydApiException( 0xC101, e );
|
||||
}
|
||||
String signAlg = certificate.getSigAlgName();
|
||||
return signAlg.toUpperCase().indexOf("SM2") >= 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user