本文整理汇总了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");
}
}
示例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 + "'");
}
} */
}
示例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;
}