增加二维码、条形码签名验签测试
This commit is contained in:
@@ -46,12 +46,14 @@ public class CertUtil {
|
||||
return (X509Certificate) CF.generateCertificate(new ByteArrayInputStream(certificateString.getBytes())); // 将文件流的证书转化为证书类
|
||||
}
|
||||
|
||||
public static String convertToPem(X509Certificate cert) throws CertificateEncodingException {
|
||||
public static String convertToPem(String cert) throws CertificateEncodingException {
|
||||
|
||||
String cert_begin = "-----BEGIN CERTIFICATE-----\n";
|
||||
String end_cert = "\n-----END CERTIFICATE-----";
|
||||
|
||||
byte[] derCert = cert.getEncoded();
|
||||
// byte[] derCert = cert.getEncoded();
|
||||
|
||||
byte[] derCert = cert.getBytes();
|
||||
String pemCertPre = new String(Base64.encode(derCert, true));
|
||||
String pemCert = cert_begin + pemCertPre + end_cert;
|
||||
return pemCert;
|
||||
@@ -98,6 +100,25 @@ public class CertUtil {
|
||||
return signAlg.toUpperCase().indexOf("SM2") >= 0;
|
||||
}
|
||||
|
||||
|
||||
public static String getDN(String cert) {
|
||||
String pemCert;
|
||||
if(cert.contains("-----BEGIN CERTIFICATE-----")){
|
||||
pemCert =cert;
|
||||
}else {
|
||||
String cert_begin = "-----BEGIN CERTIFICATE-----\n";
|
||||
String end_cert = "\n-----END CERTIFICATE-----";
|
||||
pemCert = cert_begin + cert + end_cert;
|
||||
}
|
||||
X509Certificate certificate = null;
|
||||
try {
|
||||
certificate = convertToX509Cert(pemCert);
|
||||
} catch (Exception e) {
|
||||
throw new SydApiException( 0xC101, e );
|
||||
}
|
||||
return certificate.getSubjectDN().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断 p7 是否是国密证书签的
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user