Why do you want to use legacyDecrypt() here instead of legacyBlockDecrypt()?

If you don't use legacyDecrypt() you also wouldn't manipulate the key like you did it in apps/files_encryption/tests/util.php L78

legacyBlockDecrypt() should always work and also remove trailing '\0' for the result.