/** * Return the encrypted digest of the specified signature. */ private byte[] getEncryptedDigest(CMSSignedData sigData) { SignerInformation signerInformation = sigData.getSignerInfos().getSigners().iterator().next(); return signerInformation.toASN1Structure().getEncryptedDigest().getOctets(); }
ASN1OctetString signedDigest = signerInfo.getEncryptedDigest(); String hashAlg = AlgorithmDictionary.lookup(signerInfo.getDigestAlgorithm()); String sigAlg = AlgorithmDictionary.getRSASignatureAlgorithm(hashAlg);
final DERTaggedObject signedAttributes = DSSASN1Utils.getSignedAttributes(signerInformation); final AlgorithmIdentifier digestEncryptionAlgorithm = signerInfo.getDigestEncryptionAlgorithm(); final ASN1OctetString encryptedDigest = signerInfo.getEncryptedDigest();
/** * Copied from org.bouncycastle.asn1.cms.SignerInfo#toASN1Object() and adapted to be able to use the custom unauthenticatedAttributes * * @param signerInfo * @param signerInfo * @param unauthenticatedAttributes @return */ private ASN1Sequence getSignerInfoEncoded(final SignerInfo signerInfo, final ASN1Encodable unauthenticatedAttributes) { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(signerInfo.getVersion()); v.add(signerInfo.getSID()); v.add(signerInfo.getDigestAlgorithm()); final DERTaggedObject signedAttributes = DSSASN1Utils.getSignedAttributes(signerInformation); if (signedAttributes != null) { v.add(signedAttributes); } v.add(signerInfo.getDigestEncryptionAlgorithm()); v.add(signerInfo.getEncryptedDigest()); if (unauthenticatedAttributes != null) { v.add(new DERTaggedObject(false, 1, unauthenticatedAttributes)); } return new DERSequence(v); }