CodeLogic.Common 4.9.104

This package has a SemVer 2.0.0 package version: 4.9.104+aa53c17.
dotnet add package CodeLogic.Common --version 4.9.104
                    
NuGet\Install-Package CodeLogic.Common -Version 4.9.104
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeLogic.Common" Version="4.9.104" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeLogic.Common" Version="4.9.104" />
                    
Directory.Packages.props
<PackageReference Include="CodeLogic.Common" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CodeLogic.Common --version 4.9.104
                    
#r "nuget: CodeLogic.Common, 4.9.104"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CodeLogic.Common@4.9.104
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CodeLogic.Common&version=4.9.104
                    
Install as a Cake Addin
#tool nuget:?package=CodeLogic.Common&version=4.9.104
                    
Install as a Cake Tool

CodeLogic.Common

NuGet License: MIT

A broad, stateless utility toolkit for CodeLogic 4 — security, ID/password generation, JSON, compression, imaging, strings, time, web, networking, caching, file handling, and reflection.

CodeLogic.Common is a grab-bag of small, dependency-light helpers used across CodeLogic applications. Almost everything is exposed as static helper classes grouped by namespace, so you call them directly — Hashing.Sha256(...), IdGenerator.NanoId(), JsonHelper.Serialize(...) — with no library instance to wire up. Many fallible operations return a framework Result / Result<T> instead of throwing, while simple helpers return plain values (string, bool, byte[]). The package also ships a CommonLibrary (ILibrary) so it participates in the CodeLogic lifecycle and health system.

Install

dotnet add package CodeLogic.Common

Quick start

The static helpers need no setup — import a namespace and call:

using CL.Common.Security;
using CL.Common.Generators;
using CL.Common.Data;

// Hashing — plain string return (lowercase hex)
string digest = Hashing.Sha256("my-secret-data");

// AES-256-GCM authenticated encryption — tampering is detected on decrypt
string cipher = Encryption.EncryptAes("top secret", "passphrase");
string plain  = Encryption.DecryptAes(cipher, "passphrase");

// A URL-safe, collision-resistant id — plain string return
string id = IdGenerator.NanoId();   // e.g. "V1StGXR8_Z5jdHi6B-myT"

// JSON — Result-based (never throws)
Result<string> json = JsonHelper.Serialize(new { name = "Ada" });   // {"name":"Ada"}

To participate in the CodeLogic lifecycle and health checks, load the library as usual — the static helpers remain available either way:

using CL.Common;

await Libraries.LoadAsync<CommonLibrary>();   // register before ConfigureAsync()
await CodeLogic.ConfigureAsync();
await CodeLogic.StartAsync();

Features

  • Security — Hashing (SHA-256/512, PBKDF2 password hash/verify, HMAC) and Encryption (AES-256-GCM for strings and bytes, key generation).
  • Generators — IdGenerator (GUID, sequential, timestamp, NanoID, URL-safe, sortable) and PasswordGenerator (passwords, passphrases, PINs, strength estimation).
  • Data & JSON — JsonHelper serialize/deserialize, file I/O, validation, merge, property extraction.
  • Conversion — TypeConverter safe Result-based conversion to int/long/double/bool/decimal/DateTime/Guid/enum.
  • Compression — CompressionHelper GZip, Brotli, and LZ4 for bytes, plus GZip-to-Base64 string helpers.
  • Strings — StringHelper (truncate, slug, case conversion, HTML strip) and StringValidator (email/URL/phone/IP/GUID checks).
  • Time — DateTimeHelper Unix timestamps, ISO 8601, age, business days, boundaries, relative strings.
  • Web — HtmlHelper, HttpClientHelper, HttpHeaderHelper, UrlHelper for HTML sanitization, typed HTTP requests, header/IP/UA parsing, and URL building.
  • Networking — NetworkPing, NetworkDns, SubnetCalculator, TraceRoute.
  • Parser / Cron — CronParser parse/validate 5-field cron and compute the next UTC occurrence.
  • Imaging — CLU_Imaging safe upload processing (pixel limit, EXIF orientation, fit, WebP), resize, crop, format conversion (JPEG/PNG/WebP), thumbnails, dimensions, Base64 — via SkiaSharp.
  • Caching — ICache / MemoryCache async typed in-process cache with per-entry TTL.
  • File handling — FileSystem async read/write/copy/move/delete, directory create, listing, size, existence.
  • Reflection — AssemblyHelper and ReflectionHelper for assembly metadata, type discovery, embedded resources, and dynamic property/method access.

Documentation

Full guide: CL.Common documentation

Requirements

  • No configuration required — CL.Common is a stateless utility library and writes no config file.
  • CodeLogic 4.9+ · .NET 10
  • SkiaSharp 3.x (imaging) · K4os.Compression.LZ4 1.x (LZ4) · Newtonsoft.Json 13.x

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.9.104 31 10/27/2026
4.9.103 30 10/27/2026
4.9.98 38 10/25/2026
4.8.93 68 9/23/2026
4.8.87 102 9/13/2026
4.8.85 59 9/12/2026
4.6.72 240 6/20/2026
4.6.69-preview 61 6/20/2026
4.5.2 128 5/24/2026
4.5.2-preview.68 92 6/20/2026
4.5.1 184 5/24/2026
4.5.1-preview.56 118 5/24/2026
4.4.2-preview.53 83 5/24/2026
4.4.1 142 5/24/2026
4.0.5 127 5/15/2026
4.0.4 128 5/9/2026
4.0.3 132 5/9/2026
3.2.12 829 4/18/2026
3.2.11 136 4/18/2026
3.2.10 133 4/18/2026
Loading failed

# CL.Common — Changelog

All notable changes to **CodeLogic.Common** are documented here. Versions follow
[Semantic Versioning](https://semver.org/).

## 2026-10-27 (4.9.104)

### Added

- `CLU_Imaging.ProcessImage(stream, ImageProcessOptions?)` → `Result<ProcessedImage>` for user uploads:
 checks the pixel count from the header **before** decoding (`MaxPixels`, default
 `CLU_Imaging.DefaultMaxPixels` = 40 megapixels; `imaging.too_large`), turns photos upright from their EXIF
 orientation (`ApplyOrientation`), scales down (never up) into `MaxWidth` × `MaxHeight`, and encodes to
 `Format` (default WebP) at `Quality` (default 85). Re-encoding drops metadata such as GPS positions.
 `ProcessedImage` carries the bytes, the final width and height, and the format.
- `CLU_Imaging.FitWithin(width, height, maxWidth, maxHeight)`: the scaled-down size for a box.
- `ResizeImage(stream, targetWidth, targetHeight, allowCrop, format, quality = 90)`: resize to another
 format than PNG.

### Fixed

- **Decompression bombs.** `ConvertImage` and `ResizeImage` decoded any image, so a small PNG claiming
 50,000 × 50,000 pixels allocated about 10 GB. They now refuse images over `DefaultMaxPixels` with
 `imaging.too_large`; `ProcessImage` makes the limit configurable.
- **Sideways phone photos.** `ConvertImage` and `ResizeImage` ignored the EXIF orientation, so portrait
 photos came out rotated. They now turn the image upright first.
- **`ResizeImage(..., allowCrop: false)` stretched the image** to exactly the target size instead of
 keeping the aspect ratio as documented; it now fits inside the target. The file overload's
 `maintainAspectRatio: true` (which maps to it) is fixed with it, and its doc for `false` now says what it
 does: scale to cover and crop.
- **Crop edges.** The cover-and-crop path truncated the scaled size and could leave a transparent row or
 column; it now rounds up. Resizing uses Mitchell cubic sampling instead of nearest-neighbour.
- `IsValidSize`, `IsValidAspectRatio` and `GetImageDimensions` read only the header instead of decoding the
 whole image (fast, and safe for huge images). Their `catch` no longer swallows `OutOfMemoryException`.

### Upgrade notes

- Images over 40 megapixels now fail `ConvertImage`/`ResizeImage` with `imaging.too_large`. Use
 `ProcessImage` with a larger `MaxPixels` if you need them.
- Output is upright: an EXIF-rotated photo comes out with width and height swapped compared to before.
- `ResizeImage(stream, w, h, allowCrop: false)` (and the file overload with `maintainAspectRatio: true`) may
 return an image smaller than `w` × `h` on one side.
- `GetImageDimensions` reports the stored size (before EXIF orientation), as it did before.

## 2026-10-27

### Security

- `HtmlHelper.Sanitize` is now an allowlist sanitizer. It used to remove only `<script>`/`<style>`
 blocks and double-quoted `on*="…"` attributes, so unquoted or single-quoted handlers
 (`<img src=x onerror=alert(1)>`), `javascript:` links, `<iframe>`, `<object>`, `<svg>`, `<form>` and
 inline styles got through. It now rebuilds the markup: the formatting elements in the new
 `SanitizeAllowedTags` (p, br, b, strong, i, em, lists, headings, blockquote, code, …) without
 attributes, links with an `href` only when it is http, https, mailto or relative (plus
 `rel="nofollow noopener noreferrer"`); script, style, iframe, object, svg and similar elements are
 removed with their content, other tags are removed and their text kept.

### Upgrade notes

- Output changes: attributes (`class`, `style`, `title`, `src`), images, tables and embeds are no longer
 kept. For rich text that needs them, use a full allowlist sanitizer such as CL.WebLogic's
 `WebHtmlSanitizer`.

## 2026-10-24

### Changed

- Requires **CodeLogic 4.9+**. The official libraries move to the 4.9 line together with the framework,
 whose live config changes the stateful libraries now use. No API changes in this library.

## 2026-09-12

### Changed

- Unified the version line with the CodeLogic framework on **4.8.x**. Every official
 library and the framework now share one `major.minor`, so a given `4.8.<patch>`
 means the same generation across all packages.
- `version.txt` moved from `4.6` to `4.8`. The patch component remains the CI run
 number, composed at pack time; `AssemblyVersion` stays pinned at `Major.Minor.0.0`
 (now `4.8.0.0`) so every patch in the line loads interchangeably.

## 2026-06-20

### Documentation

- Full rewrite of the README and docs to house style. The README is now concise
 Markdown-only (renders on both GitHub and NuGet): install, quick start showing the
 static helpers and the optional `CommonLibrary` load, a grouped feature list, and a
 link to the docs site. Notes that `CL.Common` is stateless and needs no configuration.
- Expanded the documentation site into a three-page set under `docs/libs/common/`:
 an **Overview** (toolkit map, how static helpers are organized by namespace, the full
 catalog table, health check), **Security & Data** (`Encryption`, `Hashing`,
 `IdGenerator`, `PasswordGenerator`/`PasswordStrength`, `JsonHelper`, `TypeConverter`,
 `CompressionHelper`), and **Utilities** (`StringHelper`/`StringValidator`,
 `DateTimeHelper`, the web helpers, the networking set, `CronParser`, `CLU_Imaging`,
 `ICache`/`MemoryCache`, `FileSystem`, and the reflection helpers). Each page documents
 per-member return types accurately — plain values vs. `Result`/`Result<T>`. No API changes.

## [4.5.2] — 2026-06-20

### Documentation

- Documented the full public surface of the toolkit in the README. Previously only
 imaging, hashing, caching, file handling, compression, and networking were listed;
 the README now also covers **Security** (`Encryption` AES-256-GCM and the `Hashing`
 PBKDF2/HMAC helpers), **Generators** (`IdGenerator`, `PasswordGenerator`),
 **Data** (`JsonHelper`), **Conversion** (`TypeConverter`), **Parser** (`CronParser`),
 **Time** (`DateTimeHelper`), **Strings** (`StringHelper`, `StringValidator`),
 **Web** (`UrlHelper`, `HtmlHelper`, `HttpClientHelper`, `HttpHeaderHelper`),
 the full **Networking** set (`NetworkPing`, `NetworkDns`, `SubnetCalculator`,
 `TraceRoute`), and **Reflection** (`AssemblyHelper`, `ReflectionHelper`).
- Corrected the Quick Start hashing example: the helper is `Hashing.Sha256(...)`
 (no `CLU_Hashing.SHA256` type exists), and clarified that GZip, Brotli, and LZ4
 are all available from `CompressionHelper`. No API changes.

## [4.5.0] — 2026-05-24

### Changed

- **Unified versioning.** All CodeLogic.Libs now share a single version line
 controlled by `version.txt` in the repo root. This is a version alignment
 release — no functional changes to this library.
## [4.0.4] — 2026-04-16

### Changed

- README + manifest refresh across every CodeLogic library for the v4
 baseline. No functional changes vs 4.0.3.
- `LibraryManifest.Version` now reads from the assembly's `AssemblyVersion`
 attribute at runtime instead of a hard-coded string.

## [4.0.2] — 2026-04-09

### Changed

- Aligned with the v4 baseline across all libraries.

## [4.0.0] — 2026-04-09

Major rewrite — republished as v4.0.0 to reset the version line under the
unified v4 baseline. All public APIs refreshed.

### Notes

- Bundles cross-platform native assets transitively for libraries that need
 them (e.g. SkiaSharp for image handling).
- Earlier history is retained in the
 [git log](https://github.com/zyntal-com/CodeLogic.Libs/commits/main/CL.Common).