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

📄 x509util.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:   X509Util.java

package org.bouncycastle.x509;

import java.io.IOException;
import java.security.*;
import java.util.*;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.jce.X509Principal;
import org.bouncycastle.util.Strings;

class X509Util
{
	static class Implementation
	{

		Object engine;
		Provider provider;

		Object getEngine()
		{
			return engine;
		}

		Provider getProvider()
		{
			return provider;
		}

		Implementation(Object engine, Provider provider)
		{
			this.engine = engine;
			this.provider = provider;
		}
	}


	private static Hashtable algorithms;
	private static Hashtable params = new Hashtable();
	private static Set noParams;

	X509Util()
	{
	}

	static DERObjectIdentifier getAlgorithmOID(String algorithmName)
	{
		algorithmName = Strings.toUpperCase(algorithmName);
		if (algorithms.containsKey(algorithmName))
			return (DERObjectIdentifier)algorithms.get(algorithmName);
		else
			return new DERObjectIdentifier(algorithmName);
	}

	static AlgorithmIdentifier getSigAlgID(DERObjectIdentifier sigOid, String algorithmName)
	{
		if (noParams.contains(sigOid))
			return new AlgorithmIdentifier(sigOid);
		algorithmName = Strings.toUpperCase(algorithmName);
		if (params.containsKey(algorithmName))
			return new AlgorithmIdentifier(sigOid, (DEREncodable)params.get(algorithmName));
		else
			return new AlgorithmIdentifier(sigOid, new DERNull());
	}

	static Iterator getAlgNames()
	{
		Enumeration e = algorithms.keys();
		List l = new ArrayList();
		for (; e.hasMoreElements(); l.add(e.nextElement()));
		return l.iterator();
	}

	static Signature getSignatureInstance(String algorithm)
		throws NoSuchAlgorithmException
	{
		return Signature.getInstance(algorithm);
	}

	static Signature getSignatureInstance(String algorithm, String provider)
		throws NoSuchProviderException, NoSuchAlgorithmException
	{
		if (provider != null)
			return Signature.getInstance(algorithm, provider);
		else
			return Signature.getInstance(algorithm);
	}

	static byte[] calculateSignature(DERObjectIdentifier sigOid, String sigName, PrivateKey key, SecureRandom random, ASN1Encodable object)
		throws IOException, NoSuchAlgorithmException, InvalidKeyException, SignatureException
	{
		if (sigOid == null)
			throw new IllegalStateException("no signature algorithm specified");
		Signature sig = getSignatureInstance(sigName);
		if (random != null)
			sig.initSign(key, random);
		else
			sig.initSign(key);
		sig.update(object.getEncoded("DER"));
		return sig.sign();
	}

	static byte[] calculateSignature(DERObjectIdentifier sigOid, String sigName, String provider, PrivateKey key, SecureRandom random, ASN1Encodable object)
		throws IOException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException
	{
		if (sigOid == null)
			throw new IllegalStateException("no signature algorithm specified");
		Signature sig = getSignatureInstance(sigName, provider);
		if (random != null)
			sig.initSign(key, random);
		else
			sig.initSign(key);
		sig.update(object.getEncoded("DER"));
		return sig.sign();
	}

	static X509Principal convertPrincipal(X500Principal principal)
	{
		return new X509Principal(principal.getEncoded());
		IOException e;
		e;
		throw new IllegalArgumentException("cannot convert principal");
	}

	static Implementation getImplementation(String baseName, String algorithm, Provider prov)
		throws NoSuchAlgorithmException
	{
		String className;
		String alias;
		for (algorithm = Strings.toUpperCase(algorithm); (alias = prov.getProperty((new StringBuilder()).append("Alg.Alias.").append(baseName).append(".").append(algorithm).toString())) != null; algorithm = alias);
		className = prov.getProperty((new StringBuilder()).append(baseName).append(".").append(algorithm).toString());
		if (className == null)
			break MISSING_BLOCK_LABEL_240;
		Class cls;
		ClassLoader clsLoader = prov.getClass().getClassLoader();
		if (clsLoader != null)
			cls = clsLoader.loadClass(className);
		else
			cls = Class.forName(className);
		return new Implementation(cls.newInstance(), prov);
		ClassNotFoundException e;
		e;
		throw new IllegalStateException((new StringBuilder()).append("algorithm ").append(algorithm).append(" in provider ").append(prov.getName()).append(" but no class \"").append(className).append("\" found!").toString());
		e;
		throw new IllegalStateException((new StringBuilder()).append("algorithm ").append(algorithm).append(" in provider ").append(prov.getName()).append(" but class \"").append(className).append("\" inaccessible!").toString());
		throw new NoSuchAlgorithmException((new StringBuilder()).append("cannot find implementation ").append(algorithm).append(" for provider ").append(prov.getName()).toString());
	}

	static Implementation getImplementation(String baseName, String algorithm)
		throws NoSuchAlgorithmException
	{
		Provider prov[] = Security.getProviders();
		for (int i = 0; i != prov.length; i++)
		{
			Implementation imp = getImplementation(baseName, Strings.toUpperCase(algorithm), prov[i]);
			if (imp != null)
				return imp;
			try
			{
				imp = getImplementation(baseName, algorithm, prov[i]);
			}
			catch (NoSuchAlgorithmException e) { }
		}

		throw new NoSuchAlgorithmException((new StringBuilder()).append("cannot find implementation ").append(algorithm).toString());
	}

	static Provider getProvider(String provider)
		throws NoSuchProviderException
	{
		Provider prov = Security.getProvider(provider);
		if (prov == null)
			throw new NoSuchProviderException((new StringBuilder()).append("Provider ").append(provider).append(" not found").toString());
		else
			return prov;
	}

	static 
	{
		algorithms = new Hashtable();
		noParams = new HashSet();
		algorithms.put("MD2WITHRSAENCRYPTION", PKCSObjectIdentifiers.md2WithRSAEncryption);
		algorithms.put("MD2WITHRSA", PKCSObjectIdentifiers.md2WithRSAEncryption);
		algorithms.put("MD5WITHRSAENCRYPTION", PKCSObjectIdentifiers.md5WithRSAEncryption);
		algorithms.put("MD5WITHRSA", PKCSObjectIdentifiers.md5WithRSAEncryption);
		algorithms.put("SHA1WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha1WithRSAEncryption);
		algorithms.put("SHA1WITHRSA", PKCSObjectIdentifiers.sha1WithRSAEncryption);
		algorithms.put("SHA256WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha256WithRSAEncryption);
		algorithms.put("SHA256WITHRSA", PKCSObjectIdentifiers.sha256WithRSAEncryption);
		algorithms.put("SHA384WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha384WithRSAEncryption);
		algorithms.put("SHA384WITHRSA", PKCSObjectIdentifiers.sha384WithRSAEncryption);
		algorithms.put("SHA512WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha512WithRSAEncryption);
		algorithms.put("SHA512WITHRSA", PKCSObjectIdentifiers.sha512WithRSAEncryption);
		algorithms.put("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
		algorithms.put("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
		algorithms.put("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
		algorithms.put("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
		algorithms.put("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
		algorithms.put("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
		algorithms.put("SHA1WITHDSA", X9ObjectIdentifiers.id_dsa_with_sha1);
		algorithms.put("DSAWITHSHA1", X9ObjectIdentifiers.id_dsa_with_sha1);
		algorithms.put("SHA1WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA1);
		algorithms.put("ECDSAWITHSHA1", X9ObjectIdentifiers.ecdsa_with_SHA1);
		noParams.add(X9ObjectIdentifiers.ecdsa_with_SHA1);
		noParams.add(X9ObjectIdentifiers.id_dsa_with_sha1);
	}
}

⌨️ 快捷键说明

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