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

📄 jceecprivatekey.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:   JCEECPrivateKey.java

package org.bouncycastle.jce.provider;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.sec.ECPrivateKeyStructure;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x9.*;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.jce.interfaces.ECPrivateKey;
import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier;
import org.bouncycastle.jce.spec.*;

public class JCEECPrivateKey
	implements ECPrivateKey, PKCS12BagAttributeCarrier
{

	private String algorithm;
	private BigInteger d;
	private ECParameterSpec ecSpec;
	private Hashtable pkcs12Attributes;
	private Vector pkcs12Ordering;

	protected JCEECPrivateKey()
	{
		algorithm = "EC";
		pkcs12Attributes = new Hashtable();
		pkcs12Ordering = new Vector();
	}

	JCEECPrivateKey(ECPrivateKey key)
	{
		algorithm = "EC";
		pkcs12Attributes = new Hashtable();
		pkcs12Ordering = new Vector();
		d = key.getD();
		algorithm = key.getAlgorithm();
		ecSpec = key.getParams();
	}

	JCEECPrivateKey(String algorithm, ECPrivateKeySpec spec)
	{
		this.algorithm = "EC";
		pkcs12Attributes = new Hashtable();
		pkcs12Ordering = new Vector();
		this.algorithm = algorithm;
		d = spec.getD();
		ecSpec = spec.getParams();
	}

	JCEECPrivateKey(String algorithm, ECPrivateKeyParameters params, ECParameterSpec spec)
	{
		this.algorithm = "EC";
		pkcs12Attributes = new Hashtable();
		pkcs12Ordering = new Vector();
		ECDomainParameters dp = params.getParameters();
		this.algorithm = algorithm;
		d = params.getD();
		if (spec == null)
			ecSpec = new ECParameterSpec(dp.getCurve(), dp.getG(), dp.getN(), dp.getH(), dp.getSeed());
		else
			ecSpec = spec;
	}

	JCEECPrivateKey(PrivateKeyInfo info)
	{
		algorithm = "EC";
		pkcs12Attributes = new Hashtable();
		pkcs12Ordering = new Vector();
		X962Parameters params = new X962Parameters((DERObject)info.getAlgorithmId().getParameters());
		if (params.isNamedCurve())
		{
			DERObjectIdentifier oid = (DERObjectIdentifier)params.getParameters();
			X9ECParameters ecP = X962NamedCurves.getByOID(oid);
			ecSpec = new ECNamedCurveParameterSpec(X962NamedCurves.getName(oid), ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
		} else
		{
			X9ECParameters ecP = new X9ECParameters((ASN1Sequence)params.getParameters());
			ecSpec = new ECParameterSpec(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
		}
		if (info.getPrivateKey() instanceof DERInteger)
		{
			DERInteger derD = (DERInteger)info.getPrivateKey();
			d = derD.getValue();
		} else
		{
			ECPrivateKeyStructure ec = new ECPrivateKeyStructure((ASN1Sequence)info.getPrivateKey());
			d = ec.getKey();
		}
	}

	public String getAlgorithm()
	{
		return algorithm;
	}

	public String getFormat()
	{
		return "PKCS#8";
	}

	public byte[] getEncoded()
	{
		ByteArrayOutputStream bOut = new ByteArrayOutputStream();
		DEROutputStream dOut = new DEROutputStream(bOut);
		X962Parameters params = null;
		if (ecSpec instanceof ECNamedCurveParameterSpec)
		{
			params = new X962Parameters(X962NamedCurves.getOID(((ECNamedCurveParameterSpec)ecSpec).getName()));
		} else
		{
			X9ECParameters ecP = new X9ECParameters(ecSpec.getCurve(), ecSpec.getG(), ecSpec.getN(), ecSpec.getH(), ecSpec.getSeed());
			params = new X962Parameters(ecP);
		}
		PrivateKeyInfo info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.getDERObject()), (new ECPrivateKeyStructure(getD())).getDERObject());
		try
		{
			dOut.writeObject(info);
			dOut.close();
		}
		catch (IOException e)
		{
			throw new RuntimeException("Error encoding EC private key");
		}
		return bOut.toByteArray();
	}

	public ECParameterSpec getParams()
	{
		return ecSpec;
	}

	public BigInteger getD()
	{
		return d;
	}

	public void setBagAttribute(DERObjectIdentifier oid, DEREncodable attribute)
	{
		pkcs12Attributes.put(oid, attribute);
		pkcs12Ordering.addElement(oid);
	}

	public DEREncodable getBagAttribute(DERObjectIdentifier oid)
	{
		return (DEREncodable)pkcs12Attributes.get(oid);
	}

	public Enumeration getBagAttributeKeys()
	{
		return pkcs12Ordering.elements();
	}
}

⌨️ 快捷键说明

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