title: PHP Sodium Decryption Returns False
body: <p>I am new to php and stackoverflow, thus some mistakes may happen. Please inform me if so and I will resolve them as soon as possible.</p>
  <p>My encrypt function:</p>
  <pre><code>function encrypt($data){
  $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
  $ciphertext = sodium_crypto_secretbox($data, $nonce, $GLOBALS['key']);
  $ciphertext = base64_encode($ciphertext);
  $ciphertext .= &quot;[-SPLIT-]&quot; . base64_encode($nonce);
  
  return $ciphertext;}
  </code></pre>
  <p>My decrypt function:</p>
  <pre><code>function decrypt($data){   
  $data = explode(&quot;[-SPLIT-]&quot;, $data);
  $ciphertext = base64_decode($data[0]);
  $nonce = base64_decode($data[1]);
  $plaintext = sodium_crypto_secretbox_open($ciphertext, $nonce, $GLOBALS['key']);
  
  if(!$plaintext){$plaintext = &quot;FAILED&quot;;}
  return $plaintext;}
  </code></pre>
  <p>I have done enough testing to know that I am passing the $ciphertext returned from the encrypt function to the decrypt function. <br /></p>
  <p>How can I make a function to return a decrypted string that was encrypted in my encrypt function?</p>