⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcertificate.java

📁 wendang for java. 124342423 432
💻 JAVA
字号:
package javasec.samples.ch09;import java.security.*;import java.security.cert.*;import java.io.*;public class TestCertificate {    // Techniques to implement this method are shown in the next chapter.    PublicKey getPublicKey(Principal p) {        return null;    }    // Implementations of this method depend on the CA in use and are    // left to the reader.    InputStream lookupCRLFile(Principal p) {        return null;    }    public java.security.cert.Certificate importCertificate(byte data[])                              throws CertificateException {        X509Certificate c = null;        try {            CertificateFactory cf = CertificateFactory.getInstance("X509");            ByteArrayInputStream bais = new ByteArrayInputStream(data);            c = (X509Certificate) cf.generateCertificate(bais);            Principal p = c.getIssuerDN();            PublicKey pk = getPublicKey(p);            c.verify(pk);            InputStream crlFile = lookupCRLFile(p);            cf = CertificateFactory.getInstance("X509CRL");            X509CRL crl = (X509CRL) cf.generateCRL(crlFile);            if (crl.isRevoked(c))                    throw new CertificateException("Certificate revoked");        } catch (NoSuchAlgorithmException nsae) {            throw new CertificateException("Can't verify certificate");        } catch (NoSuchProviderException nspe) {            throw new CertificateException("Can't verify certificate");        } catch (SignatureException se) {            throw new CertificateException("Can't verify certificate");        } catch (InvalidKeyException ike) {            throw new CertificateException("Can't verify certificate");        } catch (CRLException ce) {            // treat as no crl        }        return c;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -