private EncryptedAssertion encryptAssertion(boolean inline) throws NoSuchAlgorithmException, NoSuchProviderException, EncryptionException { Credential symmetricCredential = SecurityTestHelper.generateKeyAndCredential(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128); assertNotNull(symmetricCredential.getSecretKey()); EncryptionParameters encParams = new EncryptionParameters(); encParams.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128); encParams.setEncryptionCredential(symmetricCredential); KeyEncryptionParameters kek = new KeyEncryptionParameters(); kek.setAlgorithm(EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSA15); kek.setEncryptionCredential(this.credential); Encrypter encrypter = new Encrypter(encParams, kek); if (inline) { encrypter.setKeyPlacement(KeyPlacement.INLINE); } else { encrypter.setKeyPlacement(KeyPlacement.PEER); } EncryptedAssertion encrypted = encrypter.encrypt(response.getAssertion().getAssertion()); return encrypted; }
@Test public void testValidateSignatureAfterDecryption() throws Exception { response.getAssertion().sign(credential); EncryptedAssertion encrypted = encryptAssertion(true); srt.getAssertions().clear(); srt.getEncryptedAssertions().add(encrypted); response.decryptAssertion(credential, false); assertTrue(response.getAssertion().verifySignature(credential.getPublicKey())); }