Pre-response Script - decode response before displaying it in Body window

encryption

#1

I’m trying to move my entire workflow into Postman.
Endpoint I’m trying to use is returning encrypted responses for anything that is returned with status code 200.
I have a C# app that I use to test this endpoint (to see decoded response) but I want to use Postman.

Currently, there is a pre-request script, but is there a pre-response script? I would like to check response status code and if it is OK (200) I would like to decode response.

Inside C# I use this code to encrypt/decrypt response in my test app:

public static string EncryptRijndael(string input, string key)
{
    var aes = new RijndaelManaged
    {
        KeySize = 256,
        BlockSize = 256,
        Padding = PaddingMode.PKCS7,
        Mode = CipherMode.CBC,
        Key = Encoding.UTF8.GetBytes(key)
    };

    aes.GenerateIV();

    var encryptor = aes.CreateEncryptor(aes.Key, aes.IV);

    byte[] buffer;
    using (var ms = new MemoryStream())
    {
        using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
        {
            byte[] bytes = Encoding.UTF8.GetBytes(input);
            cs.Write(bytes, 0, bytes.Length);
        }
        buffer = ms.ToArray();
    }

    buffer = buffer.Concat(aes.IV).ToArray();

    aes.Dispose();
    return Convert.ToBase64String(buffer);
}

public static string DecryptRijndael(string input, string key)
{
    var aes = new RijndaelManaged
    {
        KeySize = 256,
        BlockSize = 256,
        Mode = CipherMode.CBC,
        Padding = PaddingMode.PKCS7,
        Key = Encoding.UTF8.GetBytes(key)
    };

    byte[] xXml = Convert.FromBase64String(input);
    var buffer = xXml.Take(xXml.Length - aes.IV.Length).ToArray();
    var iv = xXml.Skip(xXml.Length - aes.IV.Length).ToArray();

    aes.IV = iv;
    var decrypt = aes.CreateDecryptor();
    byte[] xBuff;
    using (var ms = new MemoryStream())
    {
        using (var cs = new CryptoStream(ms, decrypt, CryptoStreamMode.Write))
        {
            cs.Write(buffer, 0, buffer.Length);
        }
        xBuff = ms.ToArray();
    }
    aes.Dispose();
    String output = Encoding.UTF8.GetString(xBuff);
    return output;
}