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" />
<PackageReference Include="DetectSecretsSharp" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=DetectSecretsSharp&version=1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
- Original Python project: Yelp/detect-secrets
- Port author: RomeCore
| Product | Versions 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.
-
.NETStandard 2.0
- System.Text.Json (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.