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


Java PKCS7.verify方法代码示例

本文整理汇总了Java中sun.security.pkcs.PKCS7.verify方法的典型用法代码示例。如果您正苦于以下问题:Java PKCS7.verify方法的具体用法?Java PKCS7.verify怎么用?Java PKCS7.verify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.security.pkcs.PKCS7的用法示例。


在下文中一共展示了PKCS7.verify方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        byte[] data = "Hello".getBytes();
        X500Name n = new X500Name("cn=Me");

        CertAndKeyGen cakg = new CertAndKeyGen("RSA", "SHA256withRSA");
        cakg.generate(1024);
        X509Certificate cert = cakg.getSelfCertificate(n, 1000);

        MessageDigest md = MessageDigest.getInstance("SHA-256");
        PKCS9Attributes authed = new PKCS9Attributes(new PKCS9Attribute[]{
            new PKCS9Attribute(PKCS9Attribute.CONTENT_TYPE_OID, ContentInfo.DATA_OID),
            new PKCS9Attribute(PKCS9Attribute.MESSAGE_DIGEST_OID, md.digest(data)),
        });

        Signature s = Signature.getInstance("SHA256withRSA");
        s.initSign(cakg.getPrivateKey());
        s.update(authed.getDerEncoding());
        byte[] sig = s.sign();

        SignerInfo signerInfo = new SignerInfo(
                n,
                cert.getSerialNumber(),
                AlgorithmId.get("SHA-256"),
                authed,
                AlgorithmId.get("SHA256withRSA"),
                sig,
                null
                );

        PKCS7 pkcs7 = new PKCS7(
                new AlgorithmId[] {signerInfo.getDigestAlgorithmId()},
                new ContentInfo(data),
                new X509Certificate[] {cert},
                new SignerInfo[] {signerInfo});

        if (pkcs7.verify(signerInfo, data) == null) {
            throw new Exception("Not verified");
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:NonStandardNames.java

示例2: verify

import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
public static void verify(byte[] sign, byte[] data)
		throws IOException, NoSuchAlgorithmException, SignatureException,
		InvalidKeyException, CertificateException, NoSuchProviderException {

	PKCS7 p7 = new PKCS7(sign);
	SignerInfo[] sis = p7.verify(data);

	// check the results of the verification
	if (sis == null)
		throw new SignatureException("Signature failed verification, data has been tampered");
/*		for (int i = 0; i < sis.length; i++) {
		SignerInfo si = sis[i];
		X509Certificate cert = si.getCertificate(p7);
		// 证书是否过期验证,如果不用系统日期可用cert.checkValidity(date);
		cert.checkValidity();
		// if (!cert.equals(rootCertificate)) {
		// //验证证书签名
		// cert.verify(rootCertificate.getPublicKey());
		// }
		// 验证dn
		if (i == 0 && dn != null) {
			X500Principal name = cert.getSubjectX500Principal();
			if (!dn.equals(name.getName(X500Principal.RFC1779))
					&& !new X500Principal(dn).equals(name))
				throw new SignatureException("Signer dn '"
						+ name.getName(X500Principal.RFC1779)
						+ "' does not matchs '" + dn + "'");
		}
	} */
}
 
开发者ID:mugua2015,项目名称:VerifySignedJar,代码行数:31,代码来源:VerfiyPKCS7Info.java

示例3: verifyJarSignature

import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
private boolean verifyJarSignature(JarFile jar) throws IOException, NoSuchAlgorithmException, SignatureException,
		InvalidKeyException, CertificateException, NoSuchProviderException {
	SignatureBean sgb = getSpecifyFileBytes(jar);
	if (sgb == null) {
		return false;
	}
	PKCS7 p7 = new PKCS7(sgb.getRsaFileBytes());
	SignerInfo[] sis = p7.verify(sgb.getSfFileBytes());
	 
	if (sis == null)
		return false;
	else
		return true;
}
 
开发者ID:mugua2015,项目名称:VerifySignedJar,代码行数:15,代码来源:VerifyJarHelper.java


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