本文整理汇总了Java中java.security.cert.X509Certificate.getNotAfter方法的典型用法代码示例。如果您正苦于以下问题:Java X509Certificate.getNotAfter方法的具体用法?Java X509Certificate.getNotAfter怎么用?Java X509Certificate.getNotAfter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.cert.X509Certificate
的用法示例。
在下文中一共展示了X509Certificate.getNotAfter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCertMessage
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
private String getCertMessage(X509Certificate cert, String host) {
CertificateFailure[] certFailures = getCertFailures();
Object[] param = new Object[7];
param[0] = host;
param[1] = cert.getSubjectDN().getName();
param[2] = cert.getNotBefore();
param[3] = cert.getNotAfter();
param[4] = cert.getIssuerDN().getName();
param[5] = getFingerprint(cert, "SHA1"); // NOI18N
param[6] = getFingerprint(cert, "MD5"); // NOI18N
String message = NbBundle.getMessage(SvnClientExceptionHandler.class, "MSG_BadCertificate", param); // NOI18N
for (CertificateFailure certFailure : certFailures) {
message = certFailure.message + message;
}
return message;
}
示例2: getCertificateInfoList
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
@Override
public List<CertificateBasicInfoModel> getCertificateInfoList() throws Exception {
reloadTrustManager();
ArrayList<CertificateBasicInfoModel> list = new ArrayList<>();
Enumeration<String> aliases = this.keyStore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
if ("X.509".equals(this.keyStore.getCertificate(alias).getType())) {
X509Certificate certificate = (X509Certificate) this.keyStore.getCertificate(alias);
try {
CertificateBasicInfoModel infoModel = new CertificateBasicInfoModel(
alias, getSha1Fingerprint(certificate), certificate.getIssuerDN().getName(),
certificate.getNotBefore(), certificate.getNotAfter(), certificate.getSigAlgName(),
certificateToString(certificate));
list.add(infoModel);
} catch (NoSuchAlgorithmException | CertificateEncodingException e) {
LOG.error("Failed to add certificate basic info model", e);
}
} else {
list.add(new CertificateBasicInfoModel(alias));
}
}
return list;
}
示例3: getCertificateValidityString
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public static String getCertificateValidityString(X509Certificate cert, Resources res) {
try {
cert.checkValidity();
} catch (CertificateExpiredException ce) {
return "EXPIRED: ";
} catch (CertificateNotYetValidException cny) {
return "NOT YET VALID: ";
}
Date certNotAfter = cert.getNotAfter();
Date now = new Date();
long timeLeft = certNotAfter.getTime() - now.getTime(); // Time left in ms
// More than 72h left, display days
// More than 3 months display months
if (timeLeft > 90l * 24 * 3600 * 1000) {
long months = getMonthsDifference(now, certNotAfter);
return res.getString(R.string.months_left, months);
} else if (timeLeft > 72 * 3600 * 1000) {
long days = timeLeft / (24 * 3600 * 1000);
return res.getString(R.string.days_left, days);
} else {
long hours = timeLeft / (3600 * 1000);
return res.getString(R.string.hours_left, hours);
}
}
示例4: DataValidade
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
* Método que retorna a Data De Validade Do Certificado Digital
*
* @param certificado
* @return
* @throws CertificadoException
*/
public static Date DataValidade(Certificado certificado) throws CertificadoException {
KeyStore keyStore = getKeyStore(certificado);
X509Certificate certificate = getCertificate(certificado, keyStore);
return certificate.getNotAfter();
}
示例5: getValidNotAfter
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public Date getValidNotAfter() {
X509Certificate cert = getCertificateList().get(0);
return cert.getNotAfter();
}
示例6: getValidityPeriod
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
* Checks how many days a given certificate is still valid.
* If the certificate is not valid any more, a negative number will be returned according to the number
* of days the certificate is already expired.
*
* @param certificate The X509Certificiate to be checked for validity period
* @return The number of days the given certificate is still valid, a negative number if already expired.
*/
public static short getValidityPeriod(X509Certificate certificate) {
Date today = Calendar.getInstance().getTime();
Date certificateExpirationDate = certificate.getNotAfter();
long diff = certificateExpirationDate.getTime() - today.getTime();
return (short) TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
}