@BeforeClass
  public void buildCredentials() throws NoSuchAlgorithmException, NoSuchProviderException {
    KeyPair rsaKeyPair = KeySupport.generateKeyPair(JCAConstants.KEY_ALGO_RSA, 2048, null);
    rsaCred1 = CredentialSupport.getSimpleCredential(rsaKeyPair.getPublic(), null);
    rsaCred1.getKeyNames().add(rsaCred1KeyName);

    KeyPair dsaKeyPair = KeySupport.generateKeyPair(JCAConstants.KEY_ALGO_DSA, 1024, null);
    dsaCred1 = CredentialSupport.getSimpleCredential(dsaKeyPair.getPublic(), null);
    dsaCred1.getKeyNames().add(dsaCred1KeyName);
  }
  /**
   * This method reads a private key file and returns a {@link PrivateKey}
   *
   * @param privateKeyLocation the location of the private key file
   * @return the created {@link PrivateKey}
   */
  private PrivateKey createPrivateKey(String privateKeyLocation) {
    PrivateKey privateKey = null;

    try {
      FileInputStream fisPrivateKey = new FileInputStream(privateKeyLocation);
      privateKey =
          KeySupport.decodePrivateKey(
              StringSupport.inputStreamToString(fisPrivateKey, null).getBytes(), null);
      fisPrivateKey.close();

    } catch (Exception e) {
      return null;
    }
    return privateKey;
  }
  /**
   * This method reads a private key file and returns a {@link PrivateKey}
   *
   * @param privateKeyLocation the location of the private key file
   * @return the created {@link PrivateKey}
   */
  private PrivateKey getPrivateKey(String privateKeyLocation) {
    PrivateKey privateKey = null;

    try {
      FileInputStream fisPrivateKey = new FileInputStream(privateKeyLocation);
      privateKey =
          KeySupport.decodePrivateKey(
              StringSupport.inputStreamToString(fisPrivateKey, null).getBytes(), null);
      fisPrivateKey.close();

    } catch (Exception e) {
      log.debug("{} Couldnt create the PrivateKey: {}", getLogPrefix(), e);
      return null;
    }
    return privateKey;
  }
  @Test
  public void testGeneratedDataCredential() throws ResolverException {
    roleDesc
        .getKeyDescriptors()
        .add(buildKeyDescriptor(rsaCred1KeyName, UsageType.ENCRYPTION, rsaCred1.getPublicKey()));

    resolver.setAutoGenerateDataEncryptionCredential(true);

    EncryptionParameters params = resolver.resolveSingle(criteriaSet);

    Assert.assertNotNull(params);
    Assert.assertEquals(
        params.getKeyTransportEncryptionCredential().getPublicKey(), rsaCred1.getPublicKey());
    Assert.assertEquals(params.getKeyTransportEncryptionAlgorithm(), defaultRSAKeyTransportAlgo);
    Assert.assertNotNull(params.getKeyTransportKeyInfoGenerator());

    Assert.assertNotNull(params.getDataEncryptionCredential());
    Assert.assertNotNull(params.getDataEncryptionCredential().getSecretKey());
    Assert.assertEquals(params.getDataEncryptionAlgorithm(), defaultAES128DataAlgo);
    Assert.assertEquals(
        KeySupport.getKeyLength(params.getDataEncryptionCredential().getSecretKey()),
        new Integer(128));
    Assert.assertNotNull(params.getDataKeyInfoGenerator());
  }