data-protection

Implement ASP.NET Core Data Protection patterns for encryption, key management, and time-limited tokens.

Updated Mar 8, 2026
One-click install
npx skills add https://github.com/AGIBuild/dotnet.CI.template --skill data-protection-agibuild
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: data-protection
Source: https://github.com/AGIBuild/dotnet.CI.template/tree/main/.cursor/skills/data-protection
Command: npx skills add https://github.com/AGIBuild/dotnet.CI.template --skill data-protection-agibuild

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Protecting sensitive data in ASP.NET Core applications is error-prone when developers hand-roll encryption, hard-code keys, or misconfigure key storage, leading to data exposure, lost keys on container restarts, and compliance failures. ## Core Features & Use Cases - Data Protection Configuration: Set up key persistence with file system, Azure Blob Storage, Redis, or certificate-based key encryption, with proper application isolation via SetApplicationName. - Encryption at Rest: Encrypt sensitive entity fields (like payment card numbers) before database storage and decrypt on retrieval using purpose-specific IDataProtector instances. - Time-Limited Tokens: Generate expiring tokens for password resets and email confirmations using ITimeLimitedDataProtector. - Use Case: When building a checkout flow, encrypt payment method details before saving to the database, protect sensitive session data during checkout, and issue one-hour password reset tokens that automatically expire. ## Quick Start Ask the AI to configure ASP.NET Core Data Protection with persistent key storage and create a service that encrypts sensitive fields before saving them to the database.

Frequently Asked Questions about data-protection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I encrypt sensitive data before saving to a database in ASP.NET Core?▼

Use the ASP.NET Core Data Protection API by creating an IDataProtector with a purpose string, then call Protect on sensitive fields before saving and Unprotect when retrieving. Store only the encrypted value plus non-sensitive display data like the last four card digits.

How do I create expiring tokens for password reset in ASP.NET Core?▼

Convert an IDataProtector to an ITimeLimitedDataProtector using ToTimeLimitedDataProtector, then call Protect with a TimeSpan lifetime. Unprotect throws a CryptographicException once the token expires, which you catch to reject invalid tokens.

Where should ASP.NET Core Data Protection keys be stored in production?▼

Persist keys to durable shared storage such as Azure Blob Storage, Redis, or a shared file system, and encrypt them at rest with a certificate or Azure Key Vault key. Ephemeral local storage loses keys on container restarts, breaking decryption of existing data.

Why does Data Protection Unprotect fail with a CryptographicException?▼

Unprotect fails when the payload was tampered with, the protecting key expired or was lost, or the application name differs from the one that protected the data. Catch CryptographicException specifically, log a warning, and return null rather than swallowing all exceptions.

Can multiple applications share the same Data Protection keys?▼

Applications can share a key ring only if they use the same application name via SetApplicationName. Different applications must set distinct application names so their protected payloads remain isolated and cannot be cross-decrypted.