本文整理汇总了Java中sun.security.pkcs.PKCS7.getSignerInfos方法的典型用法代码示例。如果您正苦于以下问题:Java PKCS7.getSignerInfos方法的具体用法?Java PKCS7.getSignerInfos怎么用?Java PKCS7.getSignerInfos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.security.pkcs.PKCS7
的用法示例。
在下文中一共展示了PKCS7.getSignerInfos方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkTimestamp
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
static void checkTimestamp(String file, String policyId, String digestAlg)
throws Exception {
try (JarFile jf = new JarFile(file)) {
JarEntry je = jf.getJarEntry("META-INF/OLD.RSA");
try (InputStream is = jf.getInputStream(je)) {
byte[] content = IOUtils.readFully(is, -1, true);
PKCS7 p7 = new PKCS7(content);
SignerInfo[] si = p7.getSignerInfos();
if (si == null || si.length == 0) {
throw new Exception("Not signed");
}
PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes()
.getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
PKCS7 tsToken = new PKCS7((byte[]) p9.getValue());
TimestampToken tt =
new TimestampToken(tsToken.getContentInfo().getData());
if (!tt.getHashAlgorithm().toString().equals(digestAlg)) {
throw new Exception("Digest alg different");
}
if (!tt.getPolicyID().equals(policyId)) {
throw new Exception("policyId different");
}
}
}
}
示例2: checkTimestamp
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
static void checkTimestamp(String file, String policyId, String digestAlg)
throws Exception {
try (JarFile jf = new JarFile(file)) {
JarEntry je = jf.getJarEntry("META-INF/OLD.RSA");
try (InputStream is = jf.getInputStream(je)) {
byte[] content = is.readAllBytes();
PKCS7 p7 = new PKCS7(content);
SignerInfo[] si = p7.getSignerInfos();
if (si == null || si.length == 0) {
throw new Exception("Not signed");
}
PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes()
.getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
PKCS7 tsToken = new PKCS7((byte[]) p9.getValue());
TimestampToken tt =
new TimestampToken(tsToken.getContentInfo().getData());
if (!tt.getHashAlgorithm().toString().equals(digestAlg)) {
throw new Exception("Digest alg different");
}
if (!tt.getPolicyID().equals(policyId)) {
throw new Exception("policyId different");
}
}
}
}
示例3: 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;
}