本文整理汇总了Java中sun.security.pkcs.PKCS7.getCertificates方法的典型用法代码示例。如果您正苦于以下问题:Java PKCS7.getCertificates方法的具体用法?Java PKCS7.getCertificates怎么用?Java PKCS7.getCertificates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.security.pkcs.PKCS7
的用法示例。
在下文中一共展示了PKCS7.getCertificates方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/**
* get certificate info
*
* @throws IOException
* @throws CertificateEncodingException
*/
public void parse() throws IOException, CertificateException {
PKCS7 pkcs7 = new PKCS7(Utils.toByteArray(in));
X509Certificate[] certificates = pkcs7.getCertificates();
certificateMetas = new ArrayList<>();
for (X509Certificate certificate : certificates) {
CertificateMeta certificateMeta = new CertificateMeta();
certificateMetas.add(certificateMeta);
byte[] bytes = certificate.getEncoded();
String certMd5 = md5Digest(bytes);
String publicKeyString = byteToHexString(bytes);
String certBase64Md5 = md5Digest(publicKeyString);
certificateMeta.setData(bytes);
certificateMeta.setCertBase64Md5(certBase64Md5);
certificateMeta.setCertMd5(certMd5);
certificateMeta.setStartDate(certificate.getNotBefore());
certificateMeta.setEndDate(certificate.getNotAfter());
certificateMeta.setSignAlgorithm(certificate.getSigAlgName());
certificateMeta.setSignAlgorithmOID(certificate.getSigAlgOID());
}
}
示例2: getPublicKey
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/**
* Retrieve public key from PKCS7 certificate
*
* @param certPath
* @return
* @throws IOException
* @throws InvalidKeySpecException
* @throws NoSuchAlgorithmException
*/
public static String getPublicKey(String certPath) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException {
File f = new File(certPath);
FileInputStream is = new FileInputStream(f);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
PKCS7 test = new PKCS7(buffer.toByteArray());
X509Certificate[] certs = test.getCertificates();
for (int i = 0; i < certs.length; i++) {
if (certs[i] != null && certs[i].getPublicKey() != null) {
return new BASE64Encoder().encode(certs[i].getPublicKey().getEncoded());
}
}
return "";
}
示例3: parsePKCS7
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/**
* Parse a PKCS#7 format CertPath from an InputStream. Return an
* unmodifiable List of the certificates.
*
* @param is the <code>InputStream</code> to read the data from
* @return an unmodifiable List of the certificates
* @exception CertificateException if an exception occurs
*/
private static List<X509Certificate> parsePKCS7(InputStream is)
throws CertificateException {
List<X509Certificate> certList;
if (is == null) {
throw new CertificateException("input stream is null");
}
try {
if (is.markSupported() == false) {
// Copy the entire input stream into an InputStream that does
// support mark
is = new ByteArrayInputStream(readAllBytes(is));
}
PKCS7 pkcs7 = new PKCS7(is);
X509Certificate[] certArray = pkcs7.getCertificates();
// certs are optional in PKCS #7
if (certArray != null) {
certList = Arrays.asList(certArray);
} else {
// no certs provided
certList = new ArrayList<X509Certificate>(0);
}
} catch (IOException ioe) {
throw new CertificateException("IOException parsing PKCS7 data: " +
ioe);
}
// Assumes that the resulting List is thread-safe. This is true
// because we ensure that it cannot be modified after construction
// and the methods in the Sun JDK 1.4 implementation of ArrayList that
// allow read-only access are thread-safe.
return Collections.unmodifiableList(certList);
}
示例4: parsePKCS7
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/**
* Parse a PKCS#7 format CertPath from an InputStream. Return an
* unmodifiable List of the certificates.
*
* @param is the <code>InputStream</code> to read the data from
* @return an unmodifiable List of the certificates
* @exception CertificateException if an exception occurs
*/
private static List<X509Certificate> parsePKCS7(InputStream is)
throws CertificateException {
List<X509Certificate> certList;
if (is == null) {
throw new CertificateException("input stream is null");
}
try {
if (is.markSupported() == false) {
// Copy the entire input stream into an InputStream that does
// support mark
is = new ByteArrayInputStream(readAllBytes(is));
};
PKCS7 pkcs7 = new PKCS7(is);
X509Certificate[] certArray = pkcs7.getCertificates();
// certs are optional in PKCS #7
if (certArray != null) {
certList = Arrays.asList(certArray);
} else {
// no certs provided
certList = new ArrayList<X509Certificate>(0);
}
} catch (IOException ioe) {
throw new CertificateException("IOException parsing PKCS7 data: " +
ioe);
}
// Assumes that the resulting List is thread-safe. This is true
// because we ensure that it cannot be modified after construction
// and the methods in the Sun JDK 1.4 implementation of ArrayList that
// allow read-only access are thread-safe.
return Collections.unmodifiableList(certList);
}
示例5: parseX509orPKCS7Cert
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
private Collection<? extends java.security.cert.Certificate>
parseX509orPKCS7Cert(InputStream is)
throws CertificateException, IOException
{
Collection<X509CertImpl> coll = new ArrayList<>();
byte[] data = readOneBlock(is);
if (data == null) {
return new ArrayList<>(0);
}
try {
PKCS7 pkcs7 = new PKCS7(data);
X509Certificate[] certs = pkcs7.getCertificates();
// certs are optional in PKCS #7
if (certs != null) {
return Arrays.asList(certs);
} else {
// no crls provided
return new ArrayList<>(0);
}
} catch (ParsingException e) {
while (data != null) {
coll.add(new X509CertImpl(data));
data = readOneBlock(is);
}
}
return coll;
}
示例6: parseX509orPKCS7Cert
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
private Collection<? extends java.security.cert.Certificate>
parseX509orPKCS7Cert(InputStream is)
throws CertificateException, IOException
{
int peekByte;
byte[] data;
PushbackInputStream pbis = new PushbackInputStream(is);
Collection<X509CertImpl> coll = new ArrayList<>();
// Test the InputStream for end-of-stream. If the stream's
// initial state is already at end-of-stream then return
// an empty collection. Otherwise, push the byte back into the
// stream and let readOneBlock look for the first certificate.
peekByte = pbis.read();
if (peekByte == -1) {
return new ArrayList<>(0);
} else {
pbis.unread(peekByte);
data = readOneBlock(pbis);
}
// If we end up with a null value after reading the first block
// then we know the end-of-stream has been reached and no certificate
// data has been found.
if (data == null) {
throw new CertificateException("No certificate data found");
}
try {
PKCS7 pkcs7 = new PKCS7(data);
X509Certificate[] certs = pkcs7.getCertificates();
// certs are optional in PKCS #7
if (certs != null) {
return Arrays.asList(certs);
} else {
// no certificates provided
return new ArrayList<>(0);
}
} catch (ParsingException e) {
while (data != null) {
coll.add(new X509CertImpl(data));
data = readOneBlock(pbis);
}
}
return coll;
}
示例7: rebuildEnvelope
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
@Override
public byte[] rebuildEnvelope(byte[] envelope) throws Exception {
// CMSSignedData cms = new CMSSignedData(envelope);
// cms.
//
// SignerInformationStore signers = cms.getSignerInfos();
//
// Collection c = signers.getSigners();
// Iterator it = c.iterator();
//
// while (it.hasNext()) {
// SignerInformation signer = (SignerInformation) it.next();
// SignerId sid = signer.getSID();
//
// Store certs = cms.getCertificates();
// Collection certCollection = certs.getMatches(signer.getSID());
// for (Object next : certCollection) {
// System.out.println(next);
// }
// }
PKCS7 pkcs7 = new PKCS7(envelope);
X509Certificate[] certs = pkcs7.getCertificates();
if (certs.length == 1) {
List<X509Certificate> path = certServ.buildPath(certs[0]);
SignerInfo[] si = pkcs7.getSignerInfos();
// for(X509Certificate next : path){
// System.out.println(next.getSubjectDN().getName());
//
// }
ContentInfo cInfo = new ContentInfo(ContentInfo.DIGESTED_DATA_OID,
null);
AlgorithmId digestAlgorithmId = new AlgorithmId(AlgorithmId.SHA_oid);
X509Certificate[] pathArray = new X509Certificate[path.size()];
int i = 0;
for (X509Certificate next : path) {
pathArray[i] = next;
i++;
}
// Create PKCS7 Signed data
PKCS7 p7 = new PKCS7(new AlgorithmId[] { digestAlgorithmId },
cInfo, pathArray, si);
// Write PKCS7 to bYteArray
ByteArrayOutputStream bOut = new DerOutputStream();
p7.encodeSignedData(bOut);
byte[] encodedPKCS7 = bOut.toByteArray();
return encodedPKCS7;
}
return envelope;
}
示例8: importPkcs7
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
public void importPkcs7(PKCS7 pkcs7) {
for (X509Certificate cert : pkcs7.getCertificates()) {
add(cert);
}
}