mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
hash & sm4 & cert(未测试)
This commit is contained in:
1 parent
e515af4123
commit
3868d65fae
26 files changed
+1873
-15
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package minsecurity.certificate.X509;
|
||||
|
||||
import java.security.*;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Date;
|
||||
|
||||
/*
|
||||
* @Author: hongyu guo
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 15:59 2021/03/05
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class X509CertUtil {
|
||||
|
||||
public static boolean verify(X509Certificate certificate, PublicKey publicKey){
|
||||
try {
|
||||
certificate.verify(publicKey);
|
||||
|
||||
} catch (CertificateException | NoSuchAlgorithmException |
|
||||
InvalidKeyException | NoSuchProviderException | SignatureException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isExpired(X509Certificate certificate){
|
||||
Date notAfter = certificate.getNotAfter();
|
||||
Date notBefore = certificate.getNotBefore();
|
||||
long now = System.currentTimeMillis();
|
||||
return now < notBefore.getTime() || now > notAfter.getTime();
|
||||
}
|
||||
|
||||
public static boolean isValid(X509Certificate certificate, PublicKey publicKey){
|
||||
boolean isExpired = isExpired(certificate);
|
||||
boolean isVerify = verify(certificate, publicKey);
|
||||
return !isExpired & isVerify;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user