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

📄 x509v2attributecertificate.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:   X509V2AttributeCertificate.java

package org.bouncycastle.x509;

import java.io.*;
import java.math.BigInteger;
import java.security.*;
import java.security.cert.*;
import java.text.ParseException;
import java.util.*;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.x509.*;
import org.bouncycastle.util.Arrays;

// Referenced classes of package org.bouncycastle.x509:
//			AttributeCertificateHolder, AttributeCertificateIssuer, X509Attribute, X509AttributeCertificate

public class X509V2AttributeCertificate
	implements X509AttributeCertificate
{

	private AttributeCertificate cert;
	private Date notBefore;
	private Date notAfter;

	public X509V2AttributeCertificate(InputStream encIn)
		throws IOException
	{
		this(AttributeCertificate.getInstance((new ASN1InputStream(encIn)).readObject()));
	}

	public X509V2AttributeCertificate(byte encoded[])
		throws IOException
	{
		this(((InputStream) (new ByteArrayInputStream(encoded))));
	}

	X509V2AttributeCertificate(AttributeCertificate cert)
		throws IOException
	{
		this.cert = cert;
		try
		{
			notAfter = cert.getAcinfo().getAttrCertValidityPeriod().getNotAfterTime().getDate();
			notBefore = cert.getAcinfo().getAttrCertValidityPeriod().getNotBeforeTime().getDate();
		}
		catch (ParseException e)
		{
			throw new IOException("invalid data structure in certificate!");
		}
	}

	public int getVersion()
	{
		return cert.getAcinfo().getVersion().getValue().intValue();
	}

	public BigInteger getSerialNumber()
	{
		return cert.getAcinfo().getSerialNumber().getValue();
	}

	public AttributeCertificateHolder getHolder()
	{
		return new AttributeCertificateHolder((ASN1Sequence)cert.getAcinfo().getHolder().toASN1Object());
	}

	public AttributeCertificateIssuer getIssuer()
	{
		return new AttributeCertificateIssuer(cert.getAcinfo().getIssuer());
	}

	public Date getNotBefore()
	{
		return notBefore;
	}

	public Date getNotAfter()
	{
		return notAfter;
	}

	public boolean[] getIssuerUniqueID()
	{
		DERBitString id = cert.getAcinfo().getIssuerUniqueID();
		if (id != null)
		{
			byte bytes[] = id.getBytes();
			boolean boolId[] = new boolean[bytes.length * 8 - id.getPadBits()];
			for (int i = 0; i != boolId.length; i++)
				boolId[i] = (bytes[i / 8] & 128 >>> i % 8) != 0;

			return boolId;
		} else
		{
			return null;
		}
	}

	public void checkValidity()
		throws CertificateExpiredException, CertificateNotYetValidException
	{
		checkValidity(new Date());
	}

	public void checkValidity(Date date)
		throws CertificateExpiredException, CertificateNotYetValidException
	{
		if (date.after(getNotAfter()))
			throw new CertificateExpiredException((new StringBuilder()).append("certificate expired on ").append(getNotAfter()).toString());
		if (date.before(getNotBefore()))
			throw new CertificateNotYetValidException((new StringBuilder()).append("certificate not valid till ").append(getNotBefore()).toString());
		else
			return;
	}

	public byte[] getSignature()
	{
		return cert.getSignatureValue().getBytes();
	}

	public final void verify(PublicKey key, String provider)
		throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException
	{
		Signature signature = null;
		if (!cert.getSignatureAlgorithm().equals(cert.getAcinfo().getSignature()))
			throw new CertificateException("Signature algorithm in certificate info not same as outer certificate");
		signature = Signature.getInstance(cert.getSignatureAlgorithm().getObjectId().getId(), provider);
		signature.initVerify(key);
		try
		{
			signature.update(cert.getAcinfo().getEncoded());
		}
		catch (IOException e)
		{
			throw new SignatureException("Exception encoding certificate info object");
		}
		if (!signature.verify(getSignature()))
			throw new InvalidKeyException("Public key presented not for certificate signature");
		else
			return;
	}

	public byte[] getEncoded()
		throws IOException
	{
		return cert.getEncoded();
	}

	public byte[] getExtensionValue(String oid)
	{
		X509Extension ext;
		ByteArrayOutputStream bOut;
		DEROutputStream dOut;
		X509Extensions extensions = cert.getAcinfo().getExtensions();
		if (extensions == null)
			break MISSING_BLOCK_LABEL_100;
		ext = extensions.getExtension(new DERObjectIdentifier(oid));
		if (ext == null)
			break MISSING_BLOCK_LABEL_100;
		bOut = new ByteArrayOutputStream();
		dOut = new DEROutputStream(bOut);
		dOut.writeObject(ext.getValue());
		return bOut.toByteArray();
		Exception e;
		e;
		throw new RuntimeException((new StringBuilder()).append("error encoding ").append(e.toString()).toString());
		return null;
	}

	private Set getExtensionOIDs(boolean critical)
	{
		X509Extensions extensions = cert.getAcinfo().getExtensions();
		if (extensions != null)
		{
			Set set = new HashSet();
			Enumeration e = extensions.oids();
			do
			{
				if (!e.hasMoreElements())
					break;
				DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
				X509Extension ext = extensions.getExtension(oid);
				if (ext.isCritical() == critical)
					set.add(oid.getId());
			} while (true);
			return set;
		} else
		{
			return null;
		}
	}

	public Set getNonCriticalExtensionOIDs()
	{
		return getExtensionOIDs(false);
	}

	public Set getCriticalExtensionOIDs()
	{
		return getExtensionOIDs(true);
	}

	public boolean hasUnsupportedCriticalExtension()
	{
		Set extensions = getCriticalExtensionOIDs();
		return extensions != null && !extensions.isEmpty();
	}

	public X509Attribute[] getAttributes()
	{
		ASN1Sequence seq = cert.getAcinfo().getAttributes();
		X509Attribute attrs[] = new X509Attribute[seq.size()];
		for (int i = 0; i != seq.size(); i++)
			attrs[i] = new X509Attribute((ASN1Encodable)seq.getObjectAt(i));

		return attrs;
	}

	public X509Attribute[] getAttributes(String oid)
	{
		ASN1Sequence seq = cert.getAcinfo().getAttributes();
		List list = new ArrayList();
		for (int i = 0; i != seq.size(); i++)
		{
			X509Attribute attr = new X509Attribute((ASN1Encodable)seq.getObjectAt(i));
			if (attr.getOID().equals(oid))
				list.add(attr);
		}

		if (list.size() == 0)
			return null;
		else
			return (X509Attribute[])(X509Attribute[])list.toArray(new X509Attribute[list.size()]);
	}

	public boolean equals(Object o)
	{
		X509AttributeCertificate other;
		if (o == this)
			return true;
		if (!(o instanceof X509AttributeCertificate))
			return false;
		other = (X509AttributeCertificate)o;
		byte b1[];
		byte b2[];
		b1 = getEncoded();
		b2 = other.getEncoded();
		return Arrays.areEqual(b1, b2);
		IOException e;
		e;
		return false;
	}

	public int hashCode()
	{
		int value;
		byte b[] = getEncoded();
		value = 0;
		for (int i = 0; i != b.length; i++)
			value ^= (b[i] & 0xff) << i % 4;

		return value;
		IOException e;
		e;
		return 0;
	}
}

⌨️ 快捷键说明

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