CmsReader { public static byte[] decryptAndVerify( byte[] encryptedData, List<X509Certificate> expectedSignatureCerts, X509Certificate recipientCertificate, PrivateKey recipientPrivateKey) { byte[] decrypted = decrypt(encryptedData, recipientCertificate, recipientPrivateKey); return verifyAndExtractPayload(decrypted, expectedSignatureCerts); } private  CmsReader(); static byte[] decryptAndVerify(
		byte[] encryptedData,
		List<X509Certificate> expectedSignatureCerts,
		X509Certificate recipientCertificate,
		PrivateKey recipientPrivateKey); static CertStore createCertStore(Collection<X509Certificate> allCerts);  }
@Test public void testDecryptAndVerify() throws Exception { KeyStore alice = X509CertBuilder.createTemporaryCert("cn1", "alice", "pass"); KeyStore bob = X509CertBuilder.createTemporaryCert("cn2", "bob", "pass"); byte[] signedAndEncrypted = CmsCreator.signAndEncrypt( "Hello World!".getBytes(StandardCharsets.UTF_8), (X509Certificate) alice.getCertificate("alice"), (PrivateKey) alice.getKey("alice", "pass".toCharArray()), (X509Certificate) bob.getCertificate("bob"), true); byte[] plain = CmsReader.decryptAndVerify( signedAndEncrypted, Arrays.asList((X509Certificate) alice.getCertificate("alice")), (X509Certificate) bob.getCertificate("bob"), (PrivateKey) bob.getKey("bob", "pass".toCharArray())); assertEquals(new String(plain, StandardCharsets.UTF_8), "Hello World!"); }