I need to verify a detached PKCS#7 Signature in Scala using BouncyCastle (version 1.54). The signed data are not enveloped in the PKCS#7 signature.
The PKCS#7 signature is performed using a single certificate.
I wrote a simple function based on the Javadoc of BouncyCastle to verify the signature:
def verify(data: File): Boolean = {
val signedData = new CMSSignedData(new CMSProcessableFile(data), Base64.decode(this.value))
val certStore = signedData.getCertificates
val signers = signedData.getSignerInfos.getSigners
val signer = signers.iterator.next
val certs = certStore.getMatches(signer.getSID)
val cert = certs.iterator.next.asInstanceOf[X509CertificateHolder]
signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert))
}
When I compile the code , I obtain the following error:
[error] LogVerifier.scala:26: type mismatch;
[error] found : org.bouncycastle.cms.SignerId
[error] required: org.bouncycastle.util.Selector[?0]
[error] val certs = certStore.getMatches(signer.getSID)
Could you please help me solve this compilation issue?
Thanks in advance!