Skip to content
AnnA Docs

Examples

Talk is cheap. Show me the code!

Below there are some implementation examples

  string decKey = "DECRYPTION_KEY";
  string encKey = "ENCRYPTION_KEY";
  string IV = form.Get("ANNAEXEC"); // IV that AnnA will send to you

  // Get post variables values (if any)
  string anotherVar = Decrypt3DES(form.Get("AnotherVar"), decKey, IV);

  string containers = JsonConvert.SerializeObject(
    new List<object>
    {
        new
        {
            PropName = "Container001",
            PropValue = new List<object>
            {
                new
                {
                    PropName = "Type",
                    PropValue = "MESSAGE"
                },
                new
                {
                    PropName = "Phrase",
                    PropValue = "The value of AnotherVar is: " + anotherVar
                }
            }
        }
    }
  );

  // Generate new IV
  TripleDESCryptoServiceProvider cryptoServiceProvider = new TripleDESCryptoServiceProvider();
  cryptoServiceProvider.GenerateIV();
  string newBase64IV = Convert.ToBase64String(cryptoServiceProvider.IV);

  string encryptedContainers = Encrypt3DES(containers, encKey, newBase64IV);
  string newEncryptedBase64IV = Encrypt3DES(newBase64IV, decKey, IV);

  var response = new HttpResponseMessage(HttpStatusCode.OK);
  response.Content = new StringContent(encryptedContainers + IV + newEncryptedBase64IV, Encoding.UTF8, "text/plain");

  return response;