crlextensions.java

来自「一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考」· Java 代码 · 共 73 行

JAVA
73
字号
/************************************************************************* *                                                                       * *  EJBCA: The OpenSource Certificate Authority                          * *                                                                       * *  This software is free software; you can redistribute it and/or       * *  modify it under the terms of the GNU Lesser General Public           * *  License as published by the Free Software Foundation; either         * *  version 2.1 of the License, or any later version.                    * *                                                                       * *  See terms of license at gnu.org.                                     * *                                                                       * *************************************************************************/package org.ejbca.util.cert;import java.io.ByteArrayInputStream;import java.io.IOException;import java.math.BigInteger;import java.security.cert.X509CRL;import org.apache.log4j.Logger;import org.bouncycastle.asn1.ASN1InputStream;import org.bouncycastle.asn1.ASN1OctetString;import org.bouncycastle.asn1.DERInteger;import org.bouncycastle.asn1.DERObject;import org.bouncycastle.asn1.x509.CRLNumber;import org.bouncycastle.asn1.x509.X509Extensions;/** * A class for reading values from CRL extensions. * * @author  Tomas Gustavsson * @version $Id: CrlExtensions.java,v 1.2 2006/07/28 07:14:16 anatom Exp $ */public class CrlExtensions {    private static Logger log = Logger.getLogger(CrlExtensions.class);    /** Returns the CRL number if it exists as a CRL exension     *      * @return the CRLnumber, or 0 if no CRL number extension was found or an error reading it occured. Never return null.     */    public static BigInteger getCrlNumber(X509CRL crl) {    	BigInteger ret = BigInteger.valueOf(0);        try {			DERObject obj = CrlExtensions.getExtensionValue(crl, X509Extensions.CRLNumber.getId());            DERInteger crlnum = CRLNumber.getInstance(obj);            ret = crlnum.getPositiveValue();		} catch (IOException e) {			log.error("Error reading CRL number extension: ", e);		}		return ret;    }    /**     * Return an Extension DERObject from a CRL     */    protected static DERObject getExtensionValue(X509CRL crl, String oid)      throws IOException {    	if (crl == null) {    		return null;    	}        byte[] bytes = crl.getExtensionValue(oid);        if (bytes == null) {            return null;        }        ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(bytes));        ASN1OctetString octs = (ASN1OctetString) aIn.readObject();        aIn = new ASN1InputStream(new ByteArrayInputStream(octs.getOctets()));        return aIn.readObject();    } //getExtensionValue}

⌨️ 快捷键说明

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