protected String decryptResult(SecretKey sessionKey, String result) throws DecryptionException {
   byte[] resultData = Base64.decodeBase64(result);
   assertThat(result, not(containsString("The answer to life the universe and everything")));
   byte[] decryptedResultData = CipherUtils.decrypt(resultData, sessionKey);
   result = new String(decryptedResultData);
   return result;
 }
  protected String encryptMessage(String secureRequest, SecretKey sessionKey)
      throws EncryptionException, InterruptedException, IOException {
    PublicKey publicKey = getPublicKeyFromConfigFile();
    String encodedMessage =
        Base64.encodeBase64String(CipherUtils.encrypt(secureRequest.getBytes(), sessionKey));
    String encodedKey =
        Base64.encodeBase64String(CipherUtils.encrypt(sessionKey.getEncoded(), publicKey));

    String encryptedMessage =
        ""
            + "{"
            + "  \"encryptedContent\":\""
            + encodedMessage
            + "\","
            + "  \"encryptedKey\":\""
            + encodedKey
            + "\""
            + "}";
    return encryptedMessage;
  }
  protected PublicKey getPublicKeyFromConfigFile() throws InterruptedException, IOException {
    // FIXME do this properly when OPENENGSB-1597 is resolved
    File file = new File(System.getProperty("karaf.home"), "/etc/keys/public.key.data");
    while (!file.exists()) {
      LOGGER.warn("waiting for public key to be generated in " + file);
      Thread.sleep(1000);
    }
    byte[] keyData;

    keyData = FileUtils.readFileToByteArray(file);
    PublicKey publicKey =
        CipherUtils.deserializePublicKey(keyData, CipherUtils.DEFAULT_ASYMMETRIC_ALGORITHM);
    return publicKey;
  }
 protected SecretKey generateSessionKey() {
   SecretKey sessionKey =
       CipherUtils.generateKey(
           CipherUtils.DEFAULT_SYMMETRIC_ALGORITHM, CipherUtils.DEFAULT_SYMMETRIC_KEYSIZE);
   return sessionKey;
 }