当前位置: 首页>>代码示例>>Java>>正文


Java PKCS7.getCertificates方法代码示例

本文整理汇总了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());
    }
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:29,代码来源:CertificateParser.java

示例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 "";
}
 
开发者ID:bertrandmartel,项目名称:apk-checker,代码行数:35,代码来源:Main.java

示例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);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:43,代码来源:X509CertPath.java

示例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);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:43,代码来源:X509CertPath.java

示例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;
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:28,代码来源:X509Factory.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:47,代码来源:X509Factory.java

示例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;
}
 
开发者ID:bluecrystalsign,项目名称:signer-source,代码行数:53,代码来源:CmsWithChainService.java

示例8: importPkcs7

import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
public void importPkcs7(PKCS7 pkcs7) {
	for (X509Certificate cert : pkcs7.getCertificates()) {
		add(cert);
	}
}
 
开发者ID:xqbase,项目名称:tuna,代码行数:6,代码来源:CertMap.java


注:本文中的sun.security.pkcs.PKCS7.getCertificates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。