{
  "synLogic": "unsigned char* $ret \u003d $api($1, $2, $3, $4, $5, $6, $7, $8, $9);",
  "help": "The ns_aes_encrypt function is used to encrypt data using the Advanced Encryption Standard (AES) algorithm. This function takes in several arguments, including the input data to be encrypted, the encryption algorithm to be used (with a default of aes-128-cbc), the encoding options for the key, initialization vector, and output, the key to be used for encryption, the initialization vector (IVEC) to be used (if applicable), and an error message to be returned in case of failure.<br />Overall, the ns_aes_encrypt function is a powerful tool for encrypting data using the AES algorithm. By providing the appropriate arguments, you can customize the encryption process to meet your specific needs.",
  "notes": "",
  "returns": "It returns ciphertext of encrypted data converted in base64 or NULL if wrong encryption algo is provided or NULL is provided for IVEC in CTR mode.",
  "arguments": "\u003ctable class\u003d\"newGuiTable\" style\u003d\"width:100%\" \u003e \u003ctr\u003e \u003cth\u003eArgument\u003c/th\u003e \u003cth\u003e Description \u003c/th\u003e \u003c/tr\u003e \u003ctr\u003e \u003ctd\u003e Input \u003c/td\u003e \u003ctd\u003e The string to be encrypted. \u003c/td\u003e \u003c/tr\u003e \u003ctr\u003e \u003ctd\u003e Input length \u003c/td\u003e \u003ctd\u003e The length of the input data. \u003c/td\u003e \u003c/tr\u003e \u003ctr\u003e \u003ctd\u003e Encryption Algorithm \u003c/td\u003e \u003ctd\u003e An encryption algorithm that can be aes-128-cbc, aes-192-cbc, aes-256-cbc, aes-128-ctr, aes-192-ctr, aes-256-ctr, aes-192-ecb. If not provided, aes_128_cbc will be used as the default. \u003c/td\u003e \u003c/tr\u003e \u003ctr\u003e \u003ctd\u003e Encoding Options \u003c/td\u003e \u003ctd\u003e  To Specify whether Key, IVEC or output is Base64 encoded or use Key as passphrase use following Encoding flags accordingly :<br /><b>NS_AES_KEY_BASE64</b>:<br />This flag indicates that the AES key is base64-encoded. The AES key is a secret key used for encryption and decryption of data. When this flag is set, the input key is expected to be base64-encoded. If this flag is not set, the input key is assumed to be raw binary data.<br /> \u003cbr /\u003e<b>NS_AES_IVEC_BASE64</b>:<br />This flag indicates that the Initialization Vector (IVEC) for the AES encryption is base64-encoded. The IVEC is a fixed-size input to the encryption algorithm, which is combined with the secret key to generate a unique ciphertext. When this flag is set, the input IVEC is expected to be base64-encoded. If this flag is not set, the input IVEC is assumed to be raw binary data.<br /> \u003cbr /\u003e<b>NS_AES_OUTPUT_BASE64</b>:<br /> This flag indicates that the output of the AES encryption should be base64-encoded. The output of the encryption algorithm is usually raw binary data, but if this flag is set, it will be converted to base64-encoded data. This can be useful for transmission or storage of the encrypted data.<br /> \u003cbr /\u003e<b>NS_AES_KEY_AS_PASSPHRASE</b>:<br /> This flag indicates that the AES key should be used as a passphrase to generate the actual key used for encryption. This can be useful if the actual key is difficult to remember or if a user-friendly passphrase is preferred. When this flag is set, the input key is treated as a passphrase and is used to generate the actual key using a key derivation function. If this flag is not set, the input key is used directly as the actual key.<br /><br />To specify multiple combinations of the encoding options, use the bitwise OR operation to combine the respective bit flags. For example, to set the options NS_AES_KEY_BASE64 and NS_AES_OUTPUT_BASE64, you would use the expression NS_AES_KEY_BASE64 | NS_AES_OUTPUT_BASE64. The resulting value can then be passed as an argument in the appropriate API function to specify the desired encoding options. \u003c/td\u003e \u003c/tr\u003e \u003ctr\u003e \u003ctd\u003e Key \u003c/td\u003e \u003ctd\u003e The text or binary string key to be use to encrypt input . It must be 16, 24, or 32 bytes long. \u003c/td\u003e \u003c/tr\u003e \u003ctr\u003e \u003ctd\u003e Key length \u003c/td\u003e \u003ctd\u003e length of key \u003c/td\u003e \u003c/tr\u003e \u003ctr\u003e \u003ctd\u003e Initialization Vector (IVEC) \u003c/td\u003e \u003ctd\u003e Initial state for a cryptographic algorithm. Values for \u003cbr /\u003e ECB (Electronic Code Book mode): not applicable, hence NULL should be passed\u003cbr /\u003eCTR (Galois/Counter Mode): can contain either text or binary value\u003cbr /\u003eCBC (Cipher Block Chaining): can contain either text or binary value \u003c/td\u003e \u003c/tr\u003e \u003ctr\u003e \u003ctd\u003e IVEC length \u003c/td\u003e \u003ctd\u003e Length of Initialization \u003c/td\u003e \u003c/tr\u003e \u003ctr\u003e \u003ctd\u003e Error Message \u003c/td\u003e \u003ctd\u003e Message to return in case of error/failure \u003c/td\u003e \u003c/tr\u003e \u003c/table\u003e",
  "parameterization": "",
  "name": "ns_aes_encrypt",
  "syntax": "unsigned char* ns_aes_encrypt(unsigned char *input, int input_len, int encryption_algo, int encoding_options, char *key, int key_len, char *initialization_vector, int ivec_len, char **err_msg)",
  "javaSyntax": "",
  "cEx": "flow()\n{\n  char *input = \"Hello, world!\";\n  int input_len = strlen(input);\n\n  char *key = \"0123456789abcdef0123456789abcdef\";\n  int key_len = strlen(key);\n\n  char *initialization_vector = \"0123456789abcdef\";\n  int ivec_len = strlen(initialization_vector);\n\n  char *err_msg = NULL;\n\n  // Set the encoding options to use base64 encoding for the key, IVEC, and output\n  int encoding_options = NS_AES_KEY_BASE64 | NS_AES_IVEC_BASE64 | NS_AES_OUTPUT_BASE64;\n\n  // Encrypt the input using AES-128-CBC algorithm and the provided key and IVEC\n  unsigned char *output = ns_aes_encrypt((unsigned char *)input, input_len, NS_AES_ALGO_128_CBC, encoding_options, key, key_len, initialization_vector, ivec_len, &err_msg);\n\n  if (output == NULL) {\n    printf(\"Encryption failed: %s\", err_msg);\n    return 1;\n  }\n\n  printf(\"Input: %s\", input);\n  printf(\"Encrypted output: %s\", output);\n}",
  "javaEx": "",
  "insertStrC": "ns_aes_encrypt(unsigned char *input, int input_len, int encryption_algo, int encoding_options, char *key, int key_len, char *initialization_vector, int ivec_len, char **err_msg);",
  "insertStrJava": "",
  "description": "The ns_aes_encrypt function is used to encrypt data using the Advanced Encryption Standard (AES) algorithm. It takes in several arguments, including the input data to be encrypted, the encryption algorithm to be used (with a default of aes-128-cbc), the encoding options for the key, initialization vector, and output, the key to be used for encryption, the initialization vector (IVEC) to be used (if applicable), and an error message to be returned in case of failure.",
  "component": [
    {
      "id": "$1",
      "type": "TEXT_VAR_PARAM",
      "label": "Input",
      "labelVarCheckbox": "Input is a program variable",
      "value": "",
      "css": "p-grid p-align-center w-100-p",
      "title": "Enter Input",
      "placeHolder": "",
      "style": "",
      "isDisabled": "",
      "validate": {
        "inputType": "Text",
        "required": true
      }
    },
	{
      "id": "$2",
      "type": "TextField",
      "label": "Input Length",
      "labelVarCheckbox": "",
      "value": "0",
      "css": "p-grid p-align-center w-100-p",
      "title": "Enter Input Length",
      "placeHolder": "",
      "style": "",
      "isDisabled": "",
      "validate": {
        "inputType": "Number",
        "required": true,
        "min": "0",
        "max": "2147483647"
      }
    },
    {
	 "id":"$3",
	 "type":"Dropdown",
	 "label":"Encryption Algorithm",
	 "labelVarCheckbox":"",
	 "value":"AES_128_CBC",
	 "css":"p-grid p-align-center w-100-p",
	 "title":"Enter encryption algorithm",
	 "placeHolder":"Select Algorithm",
	 "style":"",
	 "isDisabled":"",
	 "list":[
		{
		   "label":"AES_128_CBC",
		   "value":"AES_128_CBC"
		},
		{
		   "label":"AES_192_CBC",
		   "value":"AES_192_CBC"
		},
		{
		   "label":"AES_256_CBC",
		   "value":"AES_256_CBC"
		},
		{
		   "label":"AES_128_CTR",
		   "value":"AES_128_CTR"
		},
		{
		   "label":"AES_192_CTR",
		   "value":"AES_192_CTR"
		},
		{
		   "label":"AES_256_CTR",
		   "value":"AES_256_CTR"
		},
		{
		   "label":"AES_192_ECB",
		   "value":"AES_192_ECB"
		}
	 ],
	 "validate":{
		"required":true
	 }
	},
	{
	 "id":"$4",
	 "type":"ENCODE_OPTIONS",
	 "label":"Base64Encode Mode",
	 "labelVarCheckbox":"",
	 "value":"",
	 "css":"p-grid p-align-center w-100-p",
	 "title":"Enter Base64Encode Options",
	 "placeHolder":"Select Base64Encode Mode",
	 "style":"",
	 "isDisabled":"",
	   "validate":{
	   "required":true
	 }
	},
	{
      "id": "$5",
      "type": "TEXT_VAR_PARAM",
      "label": "Key",
      "labelVarCheckbox": "Input key is a program variable",
      "value": "",
      "css": "p-grid p-align-center w-100-p",
      "title": "Enter key",
      "placeHolder": "",
      "style": "",
      "isDisabled": "",
      "validate": {
        "inputType": "Text",
        "required": true
      }
    },
	{
      "id": "$6",
      "type": "TextField",
      "label": "Key Length",
      "labelVarCheckbox": "",
      "value": "0",
      "css": "p-grid p-align-center w-100-p",
      "title": "Enter key length",
      "placeHolder": "",
      "style": "",
      "isDisabled": "",
      "validate": {
        "inputType": "Number",
        "required": true,
        "min": "0",
        "max": "2147483647"
      }
    },
	{
      "id": "$7",
      "type": "TEXT_VAR_PARAM",
      "label": "Initialization Vector (IVEC)",
      "labelVarCheckbox": "IVEC text is a program variable",
      "value": "",
      "css": "p-grid p-align-center w-100-p",
      "title": "Enter Initialization Vector",
      "placeHolder": "NULL",
      "style": "",
      "isDisabled": "",
      "validate": {
        "inputType": "Text",
        "required": false
      }
    },
	{
      "id": "$8",
      "type": "TextField",
      "label": "IVEC Length",
      "labelVarCheckbox": "",
      "value": "0",
      "css": "p-grid p-align-center w-100-p",
      "title": "Enter IVEC length",
      "placeHolder": "",
      "style": "",
      "isDisabled": "",
      "validate": {
        "inputType": "Number",
        "required": true,
        "min": "0",
        "max": "2147483647"
      }
    },
	{
      "id": "$9",
      "type": "TextField",
      "label": "Error Message Buffer Pointer",
      "labelVarCheckbox": "",
      "value": "",
      "css": "p-grid p-align-center w-100-p",
      "title": "Enter error message",
      "placeHolder": "",
      "style": "",
      "quotes": false,
      "isDisabled": "",
      "validate": {
        "inputType": "Text",
        "required": true
      }
    },
    {
	  "id": "$ret",
	  "type": "TextField",
	  "label": "Return Variable (Pointer)",
	  "labelVarCheckbox": "",
	  "value": "",
	  "css": "p-grid p-align-center w-100-p",
	  "title": "First character must be Alpha.\r\nOther characters are Alpha, Numeric or Underscore",
	  "placeHolder": "",
	  "style": "",
	  "isDisabled": "",
	  "validate": {
		"inputType": "Text",
		"pattern": "^[a-zA-Z][a-zA-Z0-9_]{0,63}$",
		"method": "isValidVar(arg)",
		"required": false
	  }
	}
  ]  
}
