📄 p7bparser.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: P7BParser.java
package jit.asn1parser.pkcs.pkcs7;
import java.io.*;
import java.util.Enumeration;
import java.util.Vector;
import jit.asn1.*;
import jit.asn1.pkcs.PKCSObjectIdentifiers;
import jit.asn1.pkcs.pkcs7.ContentInfo;
import jit.asn1.pkcs.pkcs7.SignedData;
import jit.asn1.x509.X509CertificateStructure;
import jit.asn1parser.x509.X509Cert;
public class P7BParser
{
public P7BParser()
{
}
public X509Cert[] parseP7b(ContentInfo contentInfo)
throws Exception
{
if(!contentInfo.getContentType().equals(PKCSObjectIdentifiers.signedData))
throw new Exception("not support p7b file typ, contentType:".concat(String.valueOf(String.valueOf(contentInfo.getContentType().getId()))));
SignedData signedData = SignedData.getInstance(contentInfo.getContent());
ASN1Set certSet = signedData.getCertificates();
Enumeration enum = certSet.getObjects();
Vector v = new Vector();
X509Cert cert = null;
for(; enum.hasMoreElements(); v.add(cert))
{
X509CertificateStructure certStruc = X509CertificateStructure.getInstance(enum.nextElement());
cert = new X509Cert(certStruc);
}
X509Cert certs[] = new X509Cert[v.size()];
v.toArray(certs);
return certs;
}
public X509Cert[] parseP7b(String fileName)
throws Exception
{
FileInputStream fin = new FileInputStream(fileName);
ASN1InputStream ais = new ASN1InputStream(fin);
ContentInfo contentInfo = ContentInfo.getInstance(ais.readObject());
ais.close();
fin.close();
return parseP7b(contentInfo);
}
public X509Cert[] parseP7b(InputStream ins)
throws Exception
{
ASN1InputStream ais = new ASN1InputStream(ins);
ContentInfo contentInfo = ContentInfo.getInstance(ais.readObject());
ins.close();
ais.close();
return parseP7b(contentInfo);
}
public ContentInfo generateP7b(X509Cert certs[])
throws Exception
{
ASN1EncodableVector v = new ASN1EncodableVector();
for(int i = 0; i < certs.length; i++)
{
X509CertificateStructure certStruc = certs[i].getCertStructure();
v.add(certStruc);
}
DERSet certSet = new DERSet(v);
DERSet algs = new DERSet();
DERSet signerInfos = new DERSet();
ContentInfo ci = new ContentInfo(PKCSObjectIdentifiers.data, null);
SignedData signedData = new SignedData(new DERInteger(1), algs, ci, certSet, null, signerInfos);
ContentInfo contentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, signedData);
return contentInfo;
}
public void generateP7bFile(X509Cert certs[], String fileName)
throws Exception
{
ContentInfo contentInfo = generateP7b(certs);
FileOutputStream fos = new FileOutputStream(fileName);
DEROutputStream dos = new DEROutputStream(fos);
dos.writeObject(contentInfo.getDERObject());
dos.close();
fos.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -