📄 pkcs10certificationrequest.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: PKCS10CertificationRequest.java
package org.bouncycastle.jce;
import java.io.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Hashtable;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.pkcs.CertificationRequest;
import org.bouncycastle.asn1.pkcs.CertificationRequestInfo;
import org.bouncycastle.asn1.x509.*;
public class PKCS10CertificationRequest extends CertificationRequest
{
private static Hashtable algorithms;
private static Hashtable oids;
private static ASN1Sequence toDERSequence(byte bytes[])
{
DERInputStream dIn;
ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
dIn = new DERInputStream(bIn);
return (ASN1Sequence)dIn.readObject();
Exception e;
e;
throw new IllegalArgumentException("badly encoded request");
}
public PKCS10CertificationRequest(byte bytes[])
{
super(toDERSequence(bytes));
}
public PKCS10CertificationRequest(ASN1Sequence sequence)
{
super(sequence);
}
public PKCS10CertificationRequest(String signatureAlgorithm, X509Name subject, PublicKey key, ASN1Set attributes, PrivateKey signingKey)
throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, SignatureException
{
this(signatureAlgorithm, subject, key, attributes, signingKey, "BC");
}
public PKCS10CertificationRequest(String signatureAlgorithm, X509Name subject, PublicKey key, ASN1Set attributes, PrivateKey signingKey, String provider)
throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, SignatureException
{
DERObjectIdentifier sigOID = (DERObjectIdentifier)algorithms.get(signatureAlgorithm.toUpperCase());
if (sigOID == null)
throw new IllegalArgumentException("Unknown signature type requested");
if (subject == null)
throw new IllegalArgumentException("subject must not be null");
if (key == null)
throw new IllegalArgumentException("public key must not be null");
sigAlgId = new AlgorithmIdentifier(sigOID, null);
byte bytes[] = key.getEncoded();
ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
DERInputStream dIn = new DERInputStream(bIn);
try
{
reqInfo = new CertificationRequestInfo(subject, new SubjectPublicKeyInfo((ASN1Sequence)dIn.readObject()), attributes);
}
catch (IOException e)
{
throw new IllegalArgumentException("can't encode public key");
}
Signature sig = null;
try
{
sig = Signature.getInstance(sigAlgId.getObjectId().getId(), provider);
}
catch (NoSuchAlgorithmException e)
{
sig = Signature.getInstance(signatureAlgorithm, provider);
}
sig.initSign(signingKey);
try
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(reqInfo);
sig.update(bOut.toByteArray());
}
catch (Exception e)
{
throw new SecurityException((new StringBuilder()).append("exception encoding TBS cert request - ").append(e).toString());
}
sigBits = new DERBitString(sig.sign());
}
public PublicKey getPublicKey()
throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
{
return getPublicKey("BC");
}
public PublicKey getPublicKey(String provider)
throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
{
SubjectPublicKeyInfo subjectPKInfo = reqInfo.getSubjectPublicKeyInfo();
X509EncodedKeySpec xspec;
AlgorithmIdentifier keyAlg;
xspec = new X509EncodedKeySpec((new DERBitString(subjectPKInfo)).getBytes());
keyAlg = subjectPKInfo.getAlgorithmId();
return KeyFactory.getInstance(keyAlg.getObjectId().getId(), provider).generatePublic(xspec);
InvalidKeySpecException e;
e;
throw new InvalidKeyException("error encoding public key");
}
public boolean verify()
throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, SignatureException
{
return verify("BC");
}
public boolean verify(String provider)
throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, SignatureException
{
Signature sig = null;
try
{
sig = Signature.getInstance(sigAlgId.getObjectId().getId(), provider);
}
catch (NoSuchAlgorithmException e)
{
if (oids.get(sigAlgId.getObjectId().getId()) != null)
{
String signatureAlgorithm = (String)oids.get(sigAlgId.getObjectId().getId());
sig = Signature.getInstance(signatureAlgorithm, provider);
}
}
sig.initVerify(getPublicKey(provider));
try
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(reqInfo);
sig.update(bOut.toByteArray());
}
catch (Exception e)
{
throw new SecurityException((new StringBuilder()).append("exception encoding TBS cert request - ").append(e).toString());
}
return sig.verify(sigBits.getBytes());
}
public byte[] getEncoded()
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
try
{
dOut.writeObject(this);
}
catch (IOException e)
{
throw new RuntimeException(e.toString());
}
return bOut.toByteArray();
}
static
{
algorithms = new Hashtable();
oids = 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("RSAWITHMD5", 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("RSAWITHSHA1", 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"));
oids.put(new DERObjectIdentifier("1.2.840.113549.1.1.5"), "SHA1WITHRSA");
oids.put(new DERObjectIdentifier("1.2.840.113549.1.1.4"), "MD5WITHRSA");
oids.put(new DERObjectIdentifier("1.2.840.113549.1.1.2"), "MD2WITHRSA");
oids.put(new DERObjectIdentifier("1.2.840.10040.4.3"), "DSAWITHSHA1");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -