Simple test class that checks SAML encryption with different algorithms.
@@ -56,8 +61,6 @@ import org.w3c.dom.Document;
*/
public class SamlEncryptionTest {
- private static final KeyPair rsaKeyPair;
-
static {
try {
KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");
@@ -68,6 +71,17 @@ public class SamlEncryptionTest {
}
}
+ private static final KeyPair rsaKeyPair;
+ private static final XMLEncryptionUtil.DecryptionKeyLocator keyLocator = data -> {
+ try {
+ Assert.assertNotNull("EncryptedData does not contain KeyInfo", data.getKeyInfo());
+ Assert.assertNotNull("EncryptedData does not contain EncryptedKey", data.getKeyInfo().itemEncryptedKey(0));
+ return Collections.singletonList(rsaKeyPair.getPrivate());
+ } catch (XMLSecurityException e) {
+ throw new IllegalArgumentException("EncryptedData does not contain KeyInfo ", e);
+ }
+ };
+
@BeforeClass
public static void beforeClass() {
Cipher cipher = null;
@@ -86,6 +100,11 @@ public class SamlEncryptionTest {
}
private void testEncryption(KeyPair pair, String alg, int keySize, String keyWrapAlg, String keyWrapHashMethod, String keyWrapMgf) throws Exception {
+ testEncryption(pair, alg, keySize, keyWrapAlg, keyWrapHashMethod, keyWrapMgf, Function.identity());
+ }
+
+ private void testEncryption(KeyPair pair, String alg, int keySize, String keyWrapAlg,
+ String keyWrapHashMethod, String keyWrapMgf, Function