Program: 175640
Project: 175640
Buggy source:
/** 
 * Verifies and decrypts a ciphertext. The ciphertext is created by   {@link SodiumLibrary#cryptoSecretBoxEasy(byte[] message,byte[] nonce,byte[] key)}
 * @param cipherText The ciphertext to decrypt
 * @param nonce The nonce used during encryption
 * @param key The key used in encryption
 * @return decrypted plaintext bytes
 * @throws SodiumLibraryException - if nonce size is incorrect or decryption fails
 * @see <a href="https://download.libsodium.org/libsodium/content/secret-key_cryptography/authenticated_encryption.html" target="_blank">Secret-key authenticated encryption</a><h3>Example</h3> <pre> <code> // don't forget to load the libsodium library first String message = "This is a message"; // generate nonce long nonceBytesLength = SodiumLibrary.cryptoSecretBoxNonceBytes(); byte[] nonceBytes = SodiumLibrary.randomBytes((int) nonceBytesLength); byte[] messageBytes = message.getBytes(); // generate the encryption key byte[] key = SodiumLibrary.randomBytes((int) SodiumLibrary.cryptoSecretBoxKeyBytes()); // encrypt byte[] cipherText = SodiumLibrary.cryptoSecretBoxEasy(messageBytes, nonceBytes, key); // now decrypt byte[] decryptedMessageBytes = SodiumLibrary.cryptoSecretBoxOpenEasy(cipherText, nonceBytes, key); String decryptedMessage; try { decryptedMessage = new String(decryptedMessageBytes, "UTF-8"); System.out.println("Decrypted message: " + decryptedMessageBytes); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } </code> </pre>
 */
public static byte[] cryptoSecretBoxOpenEasy(byte[] cipherText,byte[] nonce,byte[] key) throws SodiumLibraryException {
  if (key.length != sodium().crypto_secretbox_keybytes()) {
    throw new SodiumLibraryException("String_Node_Str" + key.length + "String_Node_Str");
  }
  if (nonce.length != sodium().crypto_secretbox_noncebytes()) {
    throw new SodiumLibraryException("String_Node_Str" + nonce.length + "String_Node_Str");
  }
  byte[] decrypted=new byte[(int)(cipherText.length - sodium().crypto_box_macbytes())];
  int rc=sodium().crypto_secretbox_open_easy(decrypted,cipherText,cipherText.length,nonce,key);
  if (rc != 0) {
    throw new SodiumLibraryException("String_Node_Str" + rc + "String_Node_Str");
  }
  return decrypted;
}

Fixed version (ground truth):
/** 
 * Verifies and decrypts a ciphertext. The ciphertext is created by   {@link SodiumLibrary#cryptoSecretBoxEasy(byte[] message,byte[] nonce,byte[] key)}
 * @param cipherText The ciphertext to decrypt
 * @param nonce The nonce used during encryption
 * @param key The key used in encryption
 * @return decrypted plaintext bytes
 * @throws SodiumLibraryException - if nonce size is incorrect or decryption fails
 * @see <a href="https://download.libsodium.org/libsodium/content/secret-key_cryptography/authenticated_encryption.html" target="_blank">Secret-key authenticated encryption</a><h3>Example</h3> <pre> <code> // don't forget to load the libsodium library first String message = "This is a message"; // generate nonce long nonceBytesLength = SodiumLibrary.cryptoSecretBoxNonceBytes(); byte[] nonceBytes = SodiumLibrary.randomBytes((int) nonceBytesLength); byte[] messageBytes = message.getBytes(); // generate the encryption key byte[] key = SodiumLibrary.randomBytes((int) SodiumLibrary.cryptoSecretBoxKeyBytes()); // encrypt byte[] cipherText = SodiumLibrary.cryptoSecretBoxEasy(messageBytes, nonceBytes, key); // now decrypt byte[] decryptedMessageBytes = SodiumLibrary.cryptoSecretBoxOpenEasy(cipherText, nonceBytes, key); String decryptedMessage; try { decryptedMessage = new String(decryptedMessageBytes, "UTF-8"); System.out.println("Decrypted message: " + decryptedMessageBytes); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } </code> </pre>
 */
public static byte[] cryptoSecretBoxOpenEasy(byte[] cipherText,byte[] nonce,byte[] key) throws SodiumLibraryException {
  if (key.length != sodium().crypto_secretbox_keybytes().intValue()) {
    throw new SodiumLibraryException("String_Node_Str" + key.length + "String_Node_Str");
  }
  if (nonce.length != sodium().crypto_secretbox_noncebytes().intValue()) {
    throw new SodiumLibraryException("String_Node_Str" + nonce.length + "String_Node_Str");
  }
  byte[] decrypted=new byte[(cipherText.length - sodium().crypto_box_macbytes().intValue())];
  int rc=sodium().crypto_secretbox_open_easy(decrypted,cipherText,cipherText.length,nonce,key);
  if (rc != 0) {
    throw new SodiumLibraryException("String_Node_Str" + rc + "String_Node_Str");
  }
  return decrypted;
}