DetectSecretsSharp 1.3.0

dotnet add package DetectSecretsSharp --version 1.3.0
                    
NuGet\Install-Package DetectSecretsSharp -Version 1.3.0
                    
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="DetectSecretsSharp" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DetectSecretsSharp" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="DetectSecretsSharp" />
                    
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 DetectSecretsSharp --version 1.3.0
                    
#r "nuget: DetectSecretsSharp, 1.3.0"
                    
#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 DetectSecretsSharp@1.3.0
                    
#: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=DetectSecretsSharp&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=DetectSecretsSharp&version=1.3.0
                    
Install as a Cake Tool

DetectSecretsSharp πŸ”

A C# port of Yelp/detect-secrets β€” an entropy-based secrets detection library.
Scans files, diffs, and ad-hoc strings for AWS keys, GitHub tokens, OpenAI keys, private keys, passwords, and 20+ other secret types.

πŸš€ Quick Start

dotnet add package DetectSecretsSharp
using DetectSecretsSharp.Core;
using DetectSecretsSharp.Plugins;

// Scan a string with all 27 built-in detectors
var results = SecretsCollection.ScanLineDefault(
    "GITHUB_TOKEN=ghp_abc123ABC456def789GHI012jkl345MNO678");

foreach (var (filename, secret) in results)
{
    Console.WriteLine($"{filename}:{secret.Type} β†’ {secret.SecretValue}");
}
// Output: adhoc-string-scan:GitHub Token β†’ ghp_abc123ABC456def789GHI012jkl345MNO678

πŸ“¦ Installation

dotnet add package DetectSecretsSharp

Or via NuGet Package Manager:

Install-Package DetectSecretsSharp

Target: .NET Standard 2.0+ (compatible with .NET Framework 4.6.1+, .NET Core 2.0+, .NET 5+)

πŸ”§ Usage

Scanning a String

// With default detectors (all 27)
var results = SecretsCollection.ScanLineDefault("AKIA1234567890ABCDEF");

// With custom detectors
var results = SecretsCollection.ScanLine(
    "password = \"supersecret\"",
    filename: "config.env",
    new KeywordDetector(), new AwsKeyDetector());

// Async version
var results = await SecretsCollection.ScanLineAsync("sk-live_...", ".env",
    new StripeDetector());

Scanning a File

var scanner = new Scanner(new DetectorBase[] {
    new AwsKeyDetector(),
    new GitHubTokenDetector(),
    new OpenAiDetector()
});

var secrets = scanner.ScanFile("config.env");

Scanning Multiple Files

var scanner = Scanner.CreateDefault();
var results = scanner.ScanFiles(new[] { "file1.env", "file2.yaml" });

// Async parallel scanning
var results = await scanner.ScanFilesAsync(new[] { "file1.env", "file2.yaml" });

Scanning a Diff

var diff = @"--- a/config.env
+++ b/config.env
@@ -0,0 +1 @@
+SLACK_TOKEN=xoxb-123456789012-123456789012-abc123def456ghi789jkl012mno345pqr";

var scanner = new Scanner(new DetectorBase[] { new SlackDetector() });
var results = scanner.ScanDiff(diff);

Working with Baseline (JSON)

// Export to baseline
var baseline = secrets.ToBaselineDictionary();
string json = JsonSerializer.Serialize(baseline);

// Load from baseline
var loaded = SecretsCollection.LoadFromBaseline(baseline);

Merge and Trim

// Merge old results (preserves verification status)
current.Merge(oldResults);

// Trim: remove false positives that no longer exist
current.Trim(scannedResults);

// Subtraction: behave like set difference
var diff = current - oldResults;

πŸ—ΊοΈ Detectors (27 built-in)

Detector Secret Type Has Verify
AwsKeyDetector AWS Access Key βœ… (STS API)
AzureStorageKeyDetector Azure Storage Account Key ❌
ArtifactoryDetector Artifactory Credentials ❌
BasicAuthDetector Basic Auth Credentials ❌
Base64HighEntropyStringDetector Base64 High Entropy String ❌
CloudantDetector Cloudant Credentials βœ…
DiscordBotTokenDetector Discord Bot Token ❌
GitHubTokenDetector GitHub Token ❌
GitLabTokenDetector GitLab Token ❌
HexHighEntropyStringDetector Hex High Entropy String ❌
IbmCloudIamDetector IBM Cloud IAM Key βœ…
IbmCosHmacDetector IBM COS HMAC Credentials βœ…
IpPublicDetector Public IP (ipv4) ❌
JwtTokenDetector JSON Web Token ❌ (format validation)
KeywordDetector Secret Keyword ❌
MailchimpDetector Mailchimp Access Key βœ…
NpmDetector NPM tokens ❌
OpenAiDetector OpenAI Token ❌
PrivateKeyDetector Private Key ❌
PypiTokenDetector PyPI Token ❌
SendGridDetector SendGrid API Token ❌
SlackDetector Slack Token βœ…
SoftlayerDetector SoftLayer Credentials βœ…
SquareOAuthDetector Square OAuth Secret ❌
StripeDetector Stripe Access Key βœ…
TelegramBotTokenDetector Telegram Bot Token βœ…
TwilioKeyDetector Twilio API Key ❌

Custom Detector

public class MyCustomDetector : RegexBasedDetector
{
    public override string SecretType => "My Custom Secret";
    protected override IEnumerable<Regex> DenyList => new[]
    {
        new Regex(@"CUSTOMKEY-[A-Z0-9]{16}", RegexOptions.Compiled)
    };
}

// Usage
var results = SecretsCollection.ScanLine(
    "CUSTOMKEY-ABCD1234EFGH5678",
    detectors: new MyCustomDetector());

βš™οΈ Async Verification

Several detectors support online verification via external APIs (AWS STS, Slack, Stripe, Telegram, etc.):

// Sync (blocks thread)
var result = detector.Verify(secret);

// Async (preferred)
var result = await detector.VerifyAsync(secret);

// With code context
var context = CodeSnippet.FromSingleLine(line, lineNumber);
var result = await detector.VerifyAsync(secret, context);

πŸ”¬ Architecture

DetectSecretsSharp
β”œβ”€β”€ Core
β”‚   β”œβ”€β”€ PotentialSecret       # Secret data model
β”‚   β”œβ”€β”€ SecretsCollection     # Collection of secrets by file
β”‚   └── Scanner               # File/diff/string scanner
β”œβ”€β”€ Plugins
β”‚   β”œβ”€β”€ DetectorBase          # Abstract base detector
β”‚   β”œβ”€β”€ RegexBasedDetector    # Regex-based detector (90% of plugins)
β”‚   └── 27 concrete detectors
└── Util
    β”œβ”€β”€ CodeSnippet           # Code context for verification
    └── FileType              # File type detection

πŸ“„ License

MIT License β€” see LICENSE.

πŸ™ Credits

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.3.0 110 6/8/2026
1.2.1 106 6/8/2026
1.2.0 104 6/8/2026
1.1.0 106 6/8/2026
1.0.1 109 6/8/2026
1.0.0 108 6/8/2026