to perform AES-256 encryption/decryption in Power Platform. I tried to read an AES key from environment variables, but I’m getting a compile-time error.
Failed to provision compute for custom code. Request failed with error
'Code: BadRequest. Message: script.csx(37,55): error CS0103: The name 'environmentvariables'
does not exist in the current context.'. The correlation Id is 'fd016ca4-92ce-43bd-baa3-e3cc8e5bc1ca'.
public class Script : ScriptBase
{
public static string OperationForEncryption = "encrypt";
public static string OperationForDecryption = "decrypt";
public static byte[] Key = Encoding.UTF8.GetBytes(@environmentvariables("siti_AES_Key"));
public static byte[] Iv = Encoding.UTF8.GetBytes("abcdef9876543210");
public static string ContentKey = "content";
public override async Task<HttpResponseMessage> ExecuteAsync()
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
if (this.Context.OperationId == OperationForEncryption)
{
var contentBody = await this.Context.Request.Content.ReadAsStringAsync();
var ans = ThroughEncryptionProcess(contentBody);
var jsonResponse = JsonConvert.SerializeObject(new { data = ans });
response.Content = new StringContent(jsonResponse, Encoding.UTF8, "application/json");
}
else if (this.Context.OperationId == OperationForDecryption)
{
var content = this.Context.Request.Headers.GetValues(ContentKey).FirstOrDefault();
var ans = ThroughDecryptionProcess(content);
response.Content = new StringContent(ans, Encoding.UTF8, "application/json");
}
return response;
}
public static string ThroughEncryptionProcess(string contentBody) { /* ... */ }
public static string ThroughDecryptionProcess(string encryptedContent) { /* ... */ }
}
![]()