Gatling: transform response (based on session-variables) and use regex/jsonpath to verify response

You might come across the same question on stackoverflow. However, i’d come to realize this might be a better medium to ask this question since it is quite specific.
My question/problem:

I have a situation where my response is encrypted. In order to decrypt it, I need to get hold of the session because there are some variables on the session that are needed to decrypt.

So far I have seen 2 options to transform a responsebody but none of them works for me:

.transformResponse(/* return something here */)

Unfortunately, I can’t get the session in this method. Thus i’m not able to decrypt it.

.check(bodyString.transform((body, session) => /* decrypt it*/).is(/*..*/))

This allows me to decrypt it, but the bodyString.transform returns a plain CheckBuilder that has few operations on it. Only simple ones like ‘is’ , ‘greaterThan’ etc. This does not make it really fluent so I can do multiple ‘jsonPath’ assertions/checks in series. Also I don’t want to decrypt it for every .check()

So my final question is: Is there some way that allows me to decrypt the response (can only be decrypted with variables on the session), and use multiple ‘jsonPath’ assertions? If I can extend anything or create something myself please let me know. (and preferably some hints because i’m not really good at scala)

If anybody can come up with some hack to decrypt it (with variables from the session) in .transformResponse()…i’m up for it.

Transform output should get cached per response so multiple downstream checks shouldn’t be an issue.

I know, this transformResponse method is something i’d like to use.
However, I don’t see a way to obtain the session within the transformResponse method. I need the session, because there are some variables there that are needed to decrypt it.

The StringBody.transform on the other hand does provide a method where I can put in an ‘Expression’ (lambda that receives the session). However, drawback there is that I can’t use multiple checks on the transformed response, because that’s already in a check(…).

Some small update.
I still haven’t figured it out.

There is one (really really ugly nasty) hack/workaround for it:

  .check(bodyBytes.transform((byteArray, session) => {
   val decrypted = /*decrypt byteArray with variables on the session*/
  bodyBytes.transform((byteArray, session) => {
  val lastResponse = session("lastResponse");[String]
}).is("The value I want to assert on my last response")

now, in the second 'check' the bodyBytes.transform method is really abused just to get some variable (lastResponse) from the session.
A downside is that you need to do this for every session. Although you can abstract it to something so it looks more clean, it really isn't.
If anybody has a better way to do this, i'm still all ears.