/dknet-skills:dknet-servicesfrom dknet-skills
Provides three independent .NET services: AES-GCM/RSA encryption with HMAC/SHA hashing, HTML/Markdown-to-PDF via PuppeteerSharp, and bracket-token template replacement. Use when wiring DI for encryption, PDF generation, or string templating.
Ships in dknet-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Three independent, explicitly-invoked services with no ProjectReference between them and no EF Core or SlimBus
coupling: DKNet.Svc.Encryption (AES-GCM, RSA, HMAC/SHA, Base64), DKNet.Svc.PdfGenerators (HTML/Markdown → PDF
via PuppeteerSharp + Markdig), and DKNet.Svc.Transformation (bracketed-token template filling). Each is safe to
add standalone. Open references/<PackageId>.md for the full API surface, options, diagnostics, and testing
notes behind any package named below.
| Package | Install | What it gives you | Depends on | Reference |
|---|---|---|---|---|
DKNet.Svc.Encryption | dotnet add package DKNet.Svc.Encryption | AES-256-GCM encrypt/decrypt, RSA encrypt/decrypt + sign/verify, HMAC-SHA256/512 + SHA-256/512 hashing, Base64/Base64URL helpers | none (DKNet) | references/DKNet.Svc.Encryption.md |
DKNet.Svc.PdfGenerators | dotnet add package DKNet.Svc.PdfGenerators | HTML string/file or Markdown file(s) → PDF, headless Chromium print pipeline | none (DKNet) | references/DKNet.Svc.PdfGenerators.md |
DKNet.Svc.Transformation | dotnet add package DKNet.Svc.Transformation | Bracketed-token template filling ([Name], {Email}, <Amount>, {{Ref}}, or a custom pair) | none (DKNet) | references/DKNet.Svc.Transformation.md |
Register all three, then fill a template, render it to PDF, and encrypt the result path — one wiring block, one pipeline:
using DKNet.Svc.Encryption;
using DKNet.Svc.Encryption.Ciphers;
using DKNet.Svc.PdfGenerators;
using DKNet.Svc.Transformation;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddTransformerService(); // ITransformerService
services.AddPdfGenerator(); // IPdfGenerator singleton
services.AddAesGcmEncryption("BASE64_256_BIT_KEY_FROM_CONFIG=="); // IAesGcmEncryption singleton
var provider = services.BuildServiceProvider();
var transformer = provider.GetRequiredService<ITransformerService>();
var pdfGenerator = provider.GetRequiredService<IPdfGenerator>();
var aesGcm = provider.GetRequiredService<IAesGcmEncryption>();
var invoice = new { CustomerName = "Ada Lovelace", Total = 128.50m };
var html = transformer.Transform("<h1>Invoice for [CustomerName]</h1><p>Total: [Total]</p>", invoice);
var pdfPath = await pdfGenerator.ConvertHtmlAsync(html, "invoice.pdf");
var reference = aesGcm.EncryptString(pdfPath);
Any one of the three lines in the registration block works alone — nothing here requires the other two packages.
AddAesGcmEncryption(key)/AddRsaEncryption(key) exactly once, at startup, with the real key sourced
from configuration or a key vault. A second call with a different key is silently ignored — both guard with
services.Any(s => s.ServiceType == typeof(...)), so the first call's key wins for the process lifetime.AddEncryptionServices() expecting a cipher. It registers only IShaHashing/IHmacHashing. Call
AddAesGcmEncryption/AddRsaEncryption explicitly to get IAesGcmEncryption/IRsaEncryption.DKNet.Svc.Encryption.Ciphers for IAesGcmEncryption/AesGcmEncryption/IRsaEncryption/
RsaEncryption, and DKNet.Svc.Encryption.Hashing for IHmacHashing/HmacHashing/IShaHashing/
ShaHashing. Only EncryptionSetup and Base64StringExtensions live at the package-root namespace.using a hand-built AesGcmEncryption/RsaEncryption. DI disposes a resolved singleton for you; a
directly-constructed instance needs an explicit using or it leaks the native handle.AddPdfGenerator(options) freezes those options into a TryAddSingleton at the first call. When two
call sites need different layouts, construct new PdfGenerator(options) directly instead of resolving
IPdfGenerator.PdfGenerator — the DI singleton, or one instance you keep across calls. Each
new PdfGenerator() launches its own Chromium browser; constructing one per request is one Chromium process
per request.Format, IsLandscape, MarginOptions, Scale, HeaderHtml, FooterHtml, and ChromePath on
PdfGeneratorOptions change the rendered PDF. Theme, CodeHighlightTheme, ModuleOptions,
TableOfContents, DocumentTitle, MetadataTitle, CustomHeadContent, KeepHtml, and
EnableAutoLanguageDetection are settable, serializable, and inert — the pipeline never reads them.PuppeteerSharp.Media.PaperFormat (or DKNet.Svc.PdfGenerators.Options.MarginOptions) when a file
imports both PuppeteerSharp.Media and DKNet.Svc.PdfGenerators.Options — the bare name MarginOptions is
ambiguous (CS0104) between the two packages' own types.PuppeteerSharp.ProcessException (Chromium fails to launch, not download) on a non-Apple ARM64 host.
Verify real PDF-rendering changes on x64 or Apple Silicon, or set ChromePath to an ARM-native Chrome install.AddTransformerService(optionFactory) is idempotent per app, not per call — the first call's optionFactory
wins. Configure every bracket style, formatter, and TokenNotFoundBehavior in that one call.IDictionary<string, string> to Transform/TransformAsync when the data source is a
dictionary. Any other IDictionary, including Dictionary<string, object>, throws ArgumentException.DKNet.Svc.Transformation resolves one flat, single-level property per
token — [Customer.Name] is looked up as a literal property named Customer.Name, not a nested path.DKNet.EfCore.Encryption (see dknet-efcore-data-security), not DKNet.Svc.Encryption, when a
database column should be encrypted transparently on save and decrypted on load.When: a service needs to protect a value (a card number, a token) using one durable key resolved from DI.
using DKNet.Svc.Encryption;
using DKNet.Svc.Encryption.Ciphers;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddAesGcmEncryption("BASE64_256_BIT_KEY_FROM_CONFIG==");
var provider = services.BuildServiceProvider();
var aesGcm = provider.GetRequiredService<IAesGcmEncryption>();
var sealedValue = aesGcm.EncryptString("4111-1111-1111-1111");
var revealed = aesGcm.DecryptString(sealedValue);
Notes: EncryptString generates a fresh random nonce every call, so encrypting the same plaintext twice
never produces the same ciphertext. DecryptString throws CryptographicException if the ciphertext, key, or
associatedData don't match what was used to encrypt.
When: an order-confirmation service signs a payload; a separate verifier only ever sees the public key.
using DKNet.Svc.Encryption.Ciphers;
using var signer = new RsaEncryption(); // fresh 2048-bit pair
var publicKeyToShare = signer.PublicKey; // Base64 PKCS#1 DER
var signature = signer.Sign("order-42:confirmed");
using var verifier = RsaEncryption.FromPublicKey(publicKeyToShare); // public-only instance
var isAuthentic = verifier.Verify("order-42:confirmed", signature);
Notes: a FromPublicKey instance throws InvalidOperationException from Decrypt/Sign — it holds no
private key. Persist signer.PrivateKey (not shown) if the signer needs to survive the process.
When: an HTTP handler must confirm a request body was signed with a shared secret before trusting it.
using DKNet.Svc.Encryption.Hashing;
var verifier = new WebhookVerifier(new HmacHashing());
var trusted = verifier.IsTrusted(rawBody: "{...}", secret: "whsec_abc", signatureHeader: "BASE64_SIGNATURE");
WebhookVerifier is a thin wrapper around IHmacHashing:
using DKNet.Svc.Encryption.Hashing;
public sealed class WebhookVerifier(IHmacHashing hmac)
{
public bool IsTrusted(string rawBody, string secret, string signatureHeader) =>
hmac.VerifySha256(rawBody, secret, signatureHeader);
}
Notes: VerifySha256 returns false on a mismatch or malformed signature — it never throws for bad input,
only for a blank message/secretKey/expectedSignature (ArgumentException).
When: a report needs a specific paper size, orientation, margins, and a running header/footer.
using DKNet.Svc.PdfGenerators;
using DKNet.Svc.PdfGenerators.Options;
var options = new PdfGeneratorOptions
{
IsLandscape = true,
MarginOptions = new MarginOptions { Top = "2cm", Bottom = "2cm", Left = "1.5cm", Right = "1.5cm" },
HeaderHtml = "<div style='font-size:10px;text-align:center;width:100%'>Monthly report</div>",
FooterHtml = "<div style='font-size:10px;text-align:center;width:100%'>" +
"<span class='pageNumber'></span> / <span class='totalPages'></span></div>"
};
var generator = new PdfGenerator(options);
var pdfPath = await generator.ConvertMarkdownFileAsync("report.md", "report.pdf");
Notes: HeaderHtml/FooterHtml being non-null is what turns Chromium's header/footer on — there is no
separate boolean switch. Scale, Theme, and the other layout-only options from Rules #7 do not apply here.
When: an email or report body has placeholders and the data is either a DTO or already keyed strings.
using DKNet.Svc.Transformation;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddTransformerService();
var transformer = services.BuildServiceProvider().GetRequiredService<ITransformerService>();
var fromObject = transformer.Transform("Hello [Name]!", new { Name = "Ada" });
var fromDictionary = transformer.Transform("Hello [Name]!", new Dictionary<string, string> { { "Name", "Ada" } });
Notes: property/key lookup is case-insensitive. A dictionary parameter must be exactly
IDictionary<string, string> (Rule #11). A token with no match throws UnResolvedTokenException unless you set
TokenNotFoundBehavior to LeaveAsIs or Remove.
When: the document itself should carry its print layout instead of hardcoded C#.
using DKNet.Svc.PdfGenerators;
using DKNet.Svc.PdfGenerators.Services;
var pdfOptions = await InlineOptionsParser.ParseYamlFrontMatter("report.md");
var generator = new PdfGenerator(pdfOptions);
var pdfPath = await generator.ConvertMarkdownFileAsync("report.md", "report.pdf");
Notes: ParseYamlFrontMatter throws InvalidDataException if the file's leading ---/<!-- block has no
matching closing delimiter. It reads the front matter itself — PdfGenerator still renders the Markdown body
underneath it.
When: combining both packages — fill a template, then convert the result, in one pipeline.
using DKNet.Svc.PdfGenerators;
using DKNet.Svc.Transformation;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddTransformerService();
services.AddPdfGenerator();
var provider = services.BuildServiceProvider();
var transformer = provider.GetRequiredService<ITransformerService>();
var pdfGenerator = provider.GetRequiredService<IPdfGenerator>();
var filledHtml = transformer.Transform(
"<h1>Invoice [InvoiceNumber]</h1><p>Billed to: [CustomerName]</p>",
new { InvoiceNumber = "INV-042", CustomerName = "Ada Lovelace" });
var pdfPath = await pdfGenerator.ConvertHtmlAsync(filledHtml, "invoice.pdf");
Notes: DKNet.Svc.PdfGenerators has no templating of its own — DKNet.Svc.Transformation is the seam that
fills the placeholders before the HTML/Markdown reaches Convert*.
Encryption: every call is synchronous, in-process, string-in/string-out. AesGcmEncryption generates a
fresh random nonce per EncryptString call and serializes encrypt/decrypt through one lock per instance. Nothing
is cached, persisted, or rotated by the package — the caller owns key lifecycle end to end.
PdfGenerators: on the first Convert* call, the instance ensures Chromium is available (skips the download
if ChromePath is set, otherwise downloads it behind a process-wide lock) and launches one headless browser,
which it keeps open and reuses for every later call on that same instance. Markdown is rendered to HTML first
(via Markdig), then the HTML is loaded into a page with no base URL and printed to PDF with PrintBackground
forced on. Disposing the instance (or the DI container shutting down) closes that browser.
Transformation: TransformerService builds its token extractors once, at construction, from
TransformOptions.DefaultDefinitions at that moment. Each Transform/TransformAsync call then: extracts every
token, resolves each one (call parameters first, then GlobalParameters, with a per-call cache that only
dedupes repeats within that one call), applies TokenNotFoundBehavior to any unresolved token, formats the
result through Formatter, and rebuilds the string in one pass.
AddPdfGenerator/AddAesGcmEncryption/AddRsaEncryption/AddTransformerService are all idempotent per
process, not per call. A later call with different options/keys is silently dropped everywhere in this
skill's three packages — register each exactly once, with the configuration you actually want, and don't
expect a second call anywhere in the composition root to change anything.PdfGenerator never fires IConversionEvents. HtmlConverting/TemplateModelCreating/TempPdfCreated
exist on the interface but nothing in the shipped pipeline raises them — don't build a feature that depends on
intercepting Markdown-to-HTML or template-model creation through it.PdfGenerator instance means a fresh Chromium browser. There is no cross-instance pool; a service
that does new PdfGenerator() per request launches a browser per request. Keep one instance (or the DI
singleton) around.Transform/TransformAsync call, not a field on the instance — reusing one ITransformerService across many
different records/requests is safe, including as a singleton if you choose to register it that way.ignoreCase on IShaHashing.Verify* has no effect. Comparison runs on already-decoded, case-normalized
bytes; the flag is read but never changes the result.IPasswordAesEncryption/PasswordAesEncryption, IAesEncryption/AesEncryption, or
EncryptionSetup.AddAesEncryption — none of these exist. The only symmetric cipher this skill's Encryption
package ships is AES-GCM via IAesGcmEncryption/AddAesGcmEncryption.PdfGenerator.GenerateFromTemplateAsync or expect a Razor/model-binding overload on
IPdfGenerator — there is no templating API in DKNet.Svc.PdfGenerators. Render the string yourself (or use
DKNet.Svc.Transformation) before calling Convert*.ICustomConverter, TransformationException, a DisabledLocalCache option, or template
syntax like {amount:currency:USD} on DKNet.Svc.Transformation — none of these exist anywhere in the
package.[Customer.Name] and expect nested-property resolution, or import
DKNet.Svc.Encryption.IAesGcmEncryption/DKNet.Svc.Encryption.IRsaEncryption (wrong namespace — they live
under .Ciphers):// no-compile
using DKNet.Svc.Encryption; // IAesGcmEncryption is NOT here — it's DKNet.Svc.Encryption.Ciphers
var services = new ServiceCollection();
services.AddAesGcmEncryption(""); // empty key throws ArgumentException, not a silent random key
var pwEnc = new PasswordAesEncryption("hunter2"); // never shipped
var doc = pdfGenerator.GenerateFromTemplateAsync("template.html", model); // no such API
var value = transformer.Transform("[Customer.Name]", customer); // dotted paths are not resolved
TokenExtractor/TokenResolver from DKNet.Svc.Transformation.TokenExtractors — both are
internal sealed; they will not compile outside the package.byte[] plumbing around the Encryption ciphers/hashers — every public method is already
string-in/string-out.dknet-packages — DKNet package router and setup order; start there if you haven't picked a package yet.dknet-efcore-data-security — transparent EF Core column encryption (DKNet.EfCore.Encryption); use it
instead of this skill's DKNet.Svc.Encryption for a database column, not a call-site value.dknet-blob-storage — blob storage adapters; pairs with DKNet.Svc.Encryption (encrypt before SaveAsync)
and DKNet.Svc.PdfGenerators (store the converted PDF) when the result needs to leave local disk.dknet-aspcore-api — minimal-API endpoints and start-up tasks; run a slow PDF conversion as a background task
from there instead of inline in a request handler.dknet-efcore-domain-model, dknet-efcore-specifications, dknet-efcore-save-pipeline, dknet-codegen,
dknet-slimbus-cqrs, dknet-idempotency — none of these compose directly with the three packages in this
skill; reach for them for the EF Core domain model, querying, the save pipeline, source generators, CQRS, and
idempotent endpoints respectively.dknet-core-utilities — foundation helpers (DKNet.Fw.Extensions, DKNet.RandomCreator); has no
relationship to this skill's packages beyond both being framework-wide utility libraries.dknet-testing — testing patterns for code built on DKNet, and for working inside the DKNet repo itself.PdfGenerator?" options table, runtime behaviour, diagnostics, gotchas, and testing notes for
HTML/Markdown → PDF conversion.
Docs: https://github.com/baoduy/DKNet/blob/dev/docs/Services/DKNet.Svc.PdfGenerators.mdWhat SKILL.md sets; muted values are Claude Code's defaults
13 skills in this plugin
/dknet-aspcore-apiCovers DKNet.AspCore.Extensions and DKNet.AspCore.Tasks. Use when writing an IEndpointConfig group, calling UseEndpointConfigs for minimal-API endpoint discovery and DKNet API versioning, mapping verbs with MapGet/MapPost/MapPut/MapPatch/MapDelete/MapPutById/MapActionById/MapParameterlessActionById, building a generic list endpoint with MapGetList/MapGetById/MapDeleteById plus PagedResponse and ListFilter, converting a FluentResults Result to ProblemDetails via .Response()/.Response<T>() or AddErrorResponses, scoping authorization per verb with [EndpointGroupScope], populating [FromClaim]/[FromRequestHeader] members via AddContextualRequestPopulation, or registering IBackgroundTask with AddBackgroundJob/AddBackgroundJobFrom to run work once at host start-up./dknet-blob-storageCovers DKNet.Svc.BlobStorage.Abstractions, the .NET blob storage abstraction (IBlobService, BlobService, BlobRequest, BlobDetails.BlobData/BlobStreamData/BlobResult/BlobDataResult, BlobServiceOptions), plus its three providers: DKNet.Svc.BlobStorage.Local (AddLocalDirectoryBlobService, path-traversal-safe filesystem storage), DKNet.Svc.BlobStorage.AwsS3 (AddS3BlobService, AWS S3 and S3-compatible endpoints like MinIO and Cloudflare R2), and DKNet.Svc.BlobStorage.AzureStorage (AddAzureStorageAdapter, managed identity, SAS URLs). Use to upload, download, list, or delete files; wire DI/IConfiguration binding; generate a public or SAS URL; stream a large upload without buffering; test with Azurite or MinIO containers; or debug FileLoadException, InvalidOperationException, UnauthorizedAccessException path-traversal, or a GetAsync miss that throws on Local but returns null on S3/Azure.Other plugins' skills for the same job
npx claudepluginhub baoduy/dknet --plugin dknet-skills