Java Code Examples for org.bouncycastle.cms.SignerInformation#toASN1Structure()
The following examples show how to use
org.bouncycastle.cms.SignerInformation#toASN1Structure() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CAdESSignatureWrapperTest.java From dss with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected void verifyOriginalDocuments(SignedDocumentValidator validator, DiagnosticData diagnosticData) { super.verifyOriginalDocuments(validator, diagnosticData); SignatureWrapper signature = diagnosticData.getSignatureById(diagnosticData.getFirstSignatureId()); XmlSignatureDigestReference signatureDigestReference = signature.getSignatureDigestReference(); assertNotNull(signatureDigestReference); List<AdvancedSignature> signatures = validator.getSignatures(); assertEquals(1, signatures.size()); CAdESSignature cadesSignature = (CAdESSignature) signatures.get(0); CMSSignedData cmsSignedData = cadesSignature.getCmsSignedData(); SignerInformationStore signerInfos = cmsSignedData.getSignerInfos(); SignerInformation signerInformation = signerInfos.iterator().next(); SignerInfo signerInfo = signerInformation.toASN1Structure(); byte[] derEncoded = DSSASN1Utils.getDEREncoded(signerInfo); byte[] digest = DSSUtils.digest(signatureDigestReference.getDigestMethod(), derEncoded); String signatureReferenceDigestValue = Utils.toBase64(signatureDigestReference.getDigestValue()); String signatureElementDigestValue = Utils.toBase64(digest); assertEquals(signatureReferenceDigestValue, signatureElementDigestValue); }
Example 2
Source File: CadesLevelBaselineLTATimestampExtractor.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
/** * 3) Fields version, sid, digestAlgorithm, signedAttrs, signatureAlgorithm, and * signature within the SignedData.signerInfos’s item corresponding to the signature being archive * time-stamped, in their order of appearance. * * @param signerInformation * @return */ private byte[] getSignedFields(final SignerInformation signerInformation) { final SignerInfo signerInfo = signerInformation.toASN1Structure(); final ASN1Integer version = signerInfo.getVersion(); final SignerIdentifier sid = signerInfo.getSID(); final AlgorithmIdentifier digestAlgorithm = signerInfo.getDigestAlgorithm(); final DERTaggedObject signedAttributes = CMSUtils.getDERSignedAttributes(signerInformation); final AlgorithmIdentifier digestEncryptionAlgorithm = signerInfo.getDigestEncryptionAlgorithm(); final ASN1OctetString encryptedDigest = signerInfo.getEncryptedDigest(); final byte[] derEncodedVersion = DSSASN1Utils.getDEREncoded(version); final byte[] derEncodedSid = DSSASN1Utils.getDEREncoded(sid); final byte[] derEncodedDigestAlgorithm = DSSASN1Utils.getDEREncoded(digestAlgorithm); final byte[] derEncodedSignedAttributes = DSSASN1Utils.getDEREncoded(signedAttributes); final byte[] derEncodedDigestEncryptionAlgorithm = DSSASN1Utils.getDEREncoded(digestEncryptionAlgorithm); final byte[] derEncodedEncryptedDigest = DSSASN1Utils.getDEREncoded(encryptedDigest); if (LOG.isDebugEnabled()) { LOG.debug("getSignedFields Version={}", Utils.toBase64(derEncodedVersion)); LOG.debug("getSignedFields Sid={}", Utils.toBase64(derEncodedSid)); LOG.debug("getSignedFields DigestAlgorithm={}", Utils.toBase64(derEncodedDigestAlgorithm)); LOG.debug("getSignedFields SignedAttributes={}", Utils.toBase64(derEncodedSignedAttributes)); LOG.debug("getSignedFields DigestEncryptionAlgorithm={}", Utils.toBase64(derEncodedDigestEncryptionAlgorithm)); LOG.debug("getSignedFields EncryptedDigest={}", Utils.toBase64(derEncodedEncryptedDigest)); } return DSSUtils.concatenate(derEncodedVersion, derEncodedSid, derEncodedDigestAlgorithm, derEncodedSignedAttributes, derEncodedDigestEncryptionAlgorithm, derEncodedEncryptedDigest); }