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

📄 x509v2crlgenerator.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   X509V2CRLGenerator.java

package org.bouncycastle.jce;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.*;
import java.security.cert.X509CRL;
import java.text.SimpleDateFormat;
import java.util.*;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.x509.*;
import org.bouncycastle.jce.provider.X509CRLObject;

public class X509V2CRLGenerator
{

	private SimpleDateFormat dateF;
	private SimpleTimeZone tz;
	private V2TBSCertListGenerator tbsGen;
	private DERObjectIdentifier sigOID;
	private AlgorithmIdentifier sigAlgId;
	private String signatureAlgorithm;
	private Hashtable extensions;
	private Vector extOrdering;
	private static Hashtable algorithms;

	public X509V2CRLGenerator()
	{
		dateF = new SimpleDateFormat("yyMMddHHmmss");
		tz = new SimpleTimeZone(0, "Z");
		extensions = null;
		extOrdering = null;
		dateF.setTimeZone(tz);
		tbsGen = new V2TBSCertListGenerator();
	}

	public void reset()
	{
		tbsGen = new V2TBSCertListGenerator();
	}

	public void setIssuerDN(X509Name issuer)
	{
		tbsGen.setIssuer(issuer);
	}

	public void setThisUpdate(Date date)
	{
		tbsGen.setThisUpdate(new DERUTCTime((new StringBuilder()).append(dateF.format(date)).append("Z").toString()));
	}

	public void setNextUpdate(Date date)
	{
		tbsGen.setNextUpdate(new DERUTCTime((new StringBuilder()).append(dateF.format(date)).append("Z").toString()));
	}

	public void addCRLEntry(BigInteger userCertificate, Date revocationDate, int reason)
	{
		tbsGen.addCRLEntry(new DERInteger(userCertificate), new DERUTCTime((new StringBuilder()).append(dateF.format(revocationDate)).append("Z").toString()), reason);
	}

	public void setSignatureAlgorithm(String signatureAlgorithm)
	{
		this.signatureAlgorithm = signatureAlgorithm;
		sigOID = (DERObjectIdentifier)algorithms.get(signatureAlgorithm.toUpperCase());
		if (sigOID == null)
		{
			throw new IllegalArgumentException("Unknown signature type requested");
		} else
		{
			sigAlgId = new AlgorithmIdentifier(sigOID, null);
			tbsGen.setSignature(sigAlgId);
			return;
		}
	}

	public void addExtension(String OID, boolean critical, DEREncodable value)
	{
		addExtension(new DERObjectIdentifier(OID), critical, value);
	}

	public void addExtension(DERObjectIdentifier OID, boolean critical, DEREncodable value)
	{
		if (extensions == null)
		{
			extensions = new Hashtable();
			extOrdering = new Vector();
		}
		ByteArrayOutputStream bOut = new ByteArrayOutputStream();
		DEROutputStream dOut = new DEROutputStream(bOut);
		try
		{
			dOut.writeObject(value);
		}
		catch (IOException e)
		{
			throw new IllegalArgumentException((new StringBuilder()).append("error encoding value: ").append(e).toString());
		}
		addExtension(OID, critical, bOut.toByteArray());
	}

	public void addExtension(String OID, boolean critical, byte value[])
	{
		addExtension(new DERObjectIdentifier(OID), critical, value);
	}

	public void addExtension(DERObjectIdentifier OID, boolean critical, byte value[])
	{
		if (extensions == null)
		{
			extensions = new Hashtable();
			extOrdering = new Vector();
		}
		extensions.put(OID, new X509Extension(critical, new DEROctetString(value)));
		extOrdering.addElement(OID);
	}

	public X509CRL generateX509CRL(PrivateKey key)
		throws SecurityException, SignatureException, InvalidKeyException
	{
		return generateX509CRL(key, "BC", null);
		NoSuchProviderException e;
		e;
		throw new SecurityException("BC provider not installed!");
	}

	public X509CRL generateX509CRL(PrivateKey key, SecureRandom random)
		throws SecurityException, SignatureException, InvalidKeyException
	{
		return generateX509CRL(key, "BC", random);
		NoSuchProviderException e;
		e;
		throw new SecurityException("BC provider not installed!");
	}

	public X509CRL generateX509CRL(PrivateKey key, String provider)
		throws NoSuchProviderException, SecurityException, SignatureException, InvalidKeyException
	{
		return generateX509CRL(key, provider, null);
	}

	public X509CRL generateX509CRL(PrivateKey key, String provider, SecureRandom random)
		throws NoSuchProviderException, SecurityException, SignatureException, InvalidKeyException
	{
		Signature sig = null;
		try
		{
			sig = Signature.getInstance(sigOID.getId(), provider);
		}
		catch (NoSuchAlgorithmException ex)
		{
			try
			{
				sig = Signature.getInstance(signatureAlgorithm, provider);
			}
			catch (NoSuchAlgorithmException e)
			{
				throw new SecurityException((new StringBuilder()).append("exception creating signature: ").append(e.toString()).toString());
			}
		}
		if (random != null)
			sig.initSign(key, random);
		else
			sig.initSign(key);
		if (extensions != null)
			tbsGen.setExtensions(new X509Extensions(extOrdering, extensions));
		org.bouncycastle.asn1.x509.TBSCertList tbsCrl = tbsGen.generateTBSCertList();
		try
		{
			ByteArrayOutputStream bOut = new ByteArrayOutputStream();
			DEROutputStream dOut = new DEROutputStream(bOut);
			dOut.writeObject(tbsCrl);
			sig.update(bOut.toByteArray());
		}
		catch (Exception e)
		{
			throw new SecurityException((new StringBuilder()).append("exception encoding TBS cert - ").append(e).toString());
		}
		ASN1EncodableVector v = new ASN1EncodableVector();
		v.add(tbsCrl);
		v.add(sigAlgId);
		v.add(new DERBitString(sig.sign()));
		return new X509CRLObject(new CertificateList(new DERSequence(v)));
	}

	static 
	{
		algorithms = new Hashtable();
		algorithms.put("MD2WITHRSAENCRYPTION", new DERObjectIdentifier("1.2.840.113549.1.1.2"));
		algorithms.put("MD2WITHRSA", new DERObjectIdentifier("1.2.840.113549.1.1.2"));
		algorithms.put("MD5WITHRSAENCRYPTION", new DERObjectIdentifier("1.2.840.113549.1.1.4"));
		algorithms.put("MD5WITHRSA", new DERObjectIdentifier("1.2.840.113549.1.1.4"));
		algorithms.put("SHA1WITHRSAENCRYPTION", new DERObjectIdentifier("1.2.840.113549.1.1.5"));
		algorithms.put("SHA1WITHRSA", new DERObjectIdentifier("1.2.840.113549.1.1.5"));
		algorithms.put("RIPEMD160WITHRSAENCRYPTION", new DERObjectIdentifier("1.3.36.3.3.1.2"));
		algorithms.put("RIPEMD160WITHRSA", new DERObjectIdentifier("1.3.36.3.3.1.2"));
		algorithms.put("SHA1WITHDSA", new DERObjectIdentifier("1.2.840.10040.4.3"));
		algorithms.put("DSAWITHSHA1", new DERObjectIdentifier("1.2.840.10040.4.3"));
		algorithms.put("SHA1WITHECDSA", new DERObjectIdentifier("1.2.840.10045.4.1"));
		algorithms.put("ECDSAWITHSHA1", new DERObjectIdentifier("1.2.840.10045.4.1"));
	}
}

⌨️ 快捷键说明

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