Sample code java below is working success .
Sample code to verify a CAdES Signature using DSS-CAdES is give below
I want same code but for C# language.
public boolean validateCADESignature(String inputSignature, String inputData) throws CMSException,
CertificateException, OperatorCreationException {
Boolean validated = false;
CAdESSignature cAdESSignature;
//Base64 decode of input signature
cAdESSignature = new CAdESSignature(Base64.getDecoder().decode(inputSignature));
ObjectMapper mapper = new ObjectMapper();
mapper.findAndRegisterModules();
//Extracting the Data enveloped inside signature
String extractedData = mapper
.convertValue(new String((byte[]) cAdESSignature.getCmsSignedData().getSignedContent().getContent(),
StandardCharsets.UTF_8), String.class);
//Is Input Data matching with the data retrieved from Signature?
// If yes, then first criteria is Valid
if (inputData.equalsIgnoreCase(extractedData)) {
//Verify the Certificase of Signature
CMSSignedData signedData = cAdESSignature.getCmsSignedData();
Store < X509CertificateHolder > store = signedData.getCertificates();
SignerInformationStore signers = signedData.getSignerInfos();
Collection < SignerInformation > c = signers.getSigners();
for (SignerInformation signer: c) {
Collection certCollection = store.getMatches(signer.getSID());
Iterator certIt = certCollection.iterator();
X509CertificateHolder certHolder = (X509CertificateHolder) certIt.next();
X509Certificate certFromSignedData;
certFromSignedData = new
JcaX509CertificateConverter().setProvider("BC").getCertificate(certHolder);
if (signer
.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(certFromSignedData))) {
//Signature is verified (second criteria met)
LOG.info("Signature verified");
validated = true;
} else {
LOG.info("Signature verification failed");
}
}
}
return validated; //Return the result of Verification
}
Expected result: valid should be true because I am checking the original data.
Expected result: invalid should be false because I am checking the fake data.