Hto3.X509CertificateHelpers
1.0.5
dotnet add package Hto3.X509CertificateHelpers --version 1.0.5
NuGet\Install-Package Hto3.X509CertificateHelpers -Version 1.0.5
<PackageReference Include="Hto3.X509CertificateHelpers" Version="1.0.5" />
paket add Hto3.X509CertificateHelpers --version 1.0.5
#r "nuget: Hto3.X509CertificateHelpers, 1.0.5"
// Install Hto3.X509CertificateHelpers as a Cake Addin #addin nuget:?package=Hto3.X509CertificateHelpers&version=1.0.5 // Install Hto3.X509CertificateHelpers as a Cake Tool #tool nuget:?package=Hto3.X509CertificateHelpers&version=1.0.5
Hto3.X509CertificateHelpers
Features
A set of extension methods to help when using X.509 Certificates solving common dev problems.
VerifyPassword
Verifies if the digital certificate password is correct.
var fs = new FileStream(@"C:\mycert.pfx", FileMode.Open);
var pass = "123456";
bool success = X509CertificateHelpers.VerifyPassword(fs, pass);
if (success)
Console.WriteLine("Good password!");
else
Console.WriteLine("Wrong password!");
GetExpirationDate
Get the expiration date of a certificate.
var fs = new FileStream(@"C:\mycert.pfx", FileMode.Open);
var pass = "123456";
DateTime date = X509CertificateHelpers.GetExpirationDate(fs, pass);
Console.WriteLine($"Expire at {date}");
GetValidUserCertificates
Gets the collection of valid certificates from the currently authenticated user's computer. See more about X509Certificate2Collection.
X509Certificate2Collection collection = X509CertificateHelpers.GetValidUserCertificates()
AskForPIN
If necessary, calls the Windows dialog box for the user to enter the digital certificate PIN code. Widely used in A3 digital certificates.
<img alt="pin" src="pin.jpg">
var certificate = new X509Certificate2(@"C:\mycert.pfx", "MyPassword");
X509CertificateHelpers.AskForPIN(certificate);
//The thread hang wait until the pin dialog ends.
GetCertificateOwnerName
Get the certificate owner name.
var certificate = new X509Certificate2(@"C:\mycert.pfx", "MyPassword");
var ownerName = X509CertificateHelpers.GetCertificateOwnerName(certificate);
Console.WriteLine($"The owner name is {ownerName}");
GetCertificateCPFCNPJ
Tries to get the CPF or CNPJ linked to the digital certificate, if it is not found, null will be returned.
var certificate = new X509Certificate2(@"C:\mycert.pfx", "MyPassword");
var cpf_or_cnpj = X509CertificateHelpers.GetCertificateCPFCNPJ(certificate);
Console.WriteLine($"The digital certificate CPF or CNPJ is {cpf_or_cnpj}");
//As is in the certificate, commonly whithout dashes, points or slashes.
SignXML
Sign a XML with a digital certificate.
Assuming the following XML content:
<?xml version="1.0" encoding="utf-8"?>
<mycontent>
<description>Bike</description>
<value>10.87</value>
</mycontent>
Then loading to sign:
var certificate = new X509Certificate2(@"C:\mycert.pfx", "MyPassword");
string signedXML = X509CertificateHelpers.SignXML(certificate, null, xmlContent);
You'll get the result:
<?xml version="1.0" encoding="utf-8"?>
<mycontent>
<description>Bike</description>
<value>10.87</value>
<Signature
xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>liQ3R4eGthWfGh6CeqNO1E9WHcE=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>dqfa8dfXp2vj+YO3q/aXj4arDKfFSeWP50ZojaqCQvDg0zamj56NEjXEAfHWcdh9D57iPM6CeAECcCrs+Ko3hFCuHrToXAq+/bDUeFqclr0xkCCCxmEKoVhZWA3/4+Sx+521peps0jEuVWBnIr6KQ35BErr35KRSkIJKH9mWsDr3ejQmkh0tbfN3dBU6mvXSYfCfDOZAp/LmHUGElKMm0iqQHN1B6nxeZGYZQhOdz3qxCdpgaaL5yZE8kU69kAfs9GAneJlUylLxQ+AeIC53ZaX+dsi3bCfqP/78g1oFdDrwQFOAda84tjjGCekNzrGsk6UUfu0I0DL7vrvpNZhxMg==</SignatureValue>
<Key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Af8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQCMnGULrDCvSHnlQ1VxVPs7UL2dhXVWW+9vl0Yd0Y78e2X/NMTm2gQeyvU9KbUNl3Y7fydbPUDTQYgLcOv/zAp1CU8euGz/6i7ALibCk6TdVVipiq+MUs6PBcZvxs/kolX3FLkUcSri5FWL3htWLSSsIzqMWKD8UZK2DNDxx8oKu1+LE2Gqh12R4Riqo5TN/DCHMvONdG8WFlxIY7d0Hc24I+L8mlqZiq6ed2kTyC7dRRpsZJchjmuzNC76oBCGbhxgo0qaO8FVBiNwZYThy3xx5aDjgYzAX9yJZVUm6h86DfpBgN8GqBqYu3ilD2dG8+Cl0Ja8Lw/PUN98NLnhkFwT</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
</mycontent>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 is compatible. 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. |
.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 is compatible. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 is compatible. 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. |
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- System.Security.Cryptography.Xml (>= 6.0.1)
-
.NETStandard 2.1
- System.Security.Cryptography.Xml (>= 6.0.1)
-
net5.0
- System.Security.Cryptography.Xml (>= 6.0.1)
-
net6.0
- System.Security.Cryptography.Xml (>= 8.0.0)
-
net7.0
- System.Security.Cryptography.Xml (>= 8.0.0)
-
net8.0
- System.Security.Cryptography.Xml (>= 8.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.