title: Encrypt/ Decrypt - Secret-key authenticated encryption in Libsodium (beginner)
body: <p>I am trying to encrypt and decrypt a simple string by following the example here <a href="https://download.libsodium.org/doc/secret-key_cryptography/authenticated_encryption.html" rel="nofollow noreferrer">Here</a></p>
  
  <pre><code>#define MESSAGE ((const unsigned char *) "test")
  #define MESSAGE_LEN 4
  #define CIPHERTEXT_LEN (crypto_secretbox_MACBYTES + MESSAGE_LEN)
  
  unsigned char key[crypto_secretbox_KEYBYTES];
  unsigned char nonce[crypto_secretbox_NONCEBYTES];
  unsigned char ciphertext[CIPHERTEXT_LEN];
  
  crypto_secretbox_keygen(key);
  randombytes_buf(nonce, sizeof nonce);
  crypto_secretbox_easy(ciphertext, MESSAGE, MESSAGE_LEN, nonce, key);
  
  unsigned char decrypted[MESSAGE_LEN];
  if (crypto_secretbox_open_easy(decrypted, ciphertext, CIPHERTEXT_LEN, nonce, 
  key) != 0) {
      /* message forged! */
  }
  </code></pre>
  
  <p>My question is: How do I get back the original text? <code>'test'</code> in this case? Libsodium seem to use <code>unsigned char*</code> throughout. All Libsodium examples seem to end with <code>"Message forged!"</code>. A followup question question, how do you convert the cipher text into a serializable format?</p>