TICS.Pks11
1.0.0
dotnet add package TICS.Pks11 --version 1.0.0
NuGet\Install-Package TICS.Pks11 -Version 1.0.0
<PackageReference Include="TICS.Pks11" Version="1.0.0" />
paket add TICS.Pks11 --version 1.0.0
#r "nuget: TICS.Pks11, 1.0.0"
// Install TICS.Pks11 as a Cake Addin #addin nuget:?package=TICS.Pks11&version=1.0.0 // Install TICS.Pks11 as a Cake Tool #tool nuget:?package=TICS.Pks11&version=1.0.0
TICS.Pks11
C# .net standard class library for exporting private key from hardwareToken, privateKey.pem, privateKey as string
Description
Find private RSA key to sign with Hardware token, private Pem File and private key
How to find private key string from hardware token?
When you work more on RSA algorithms, you need private key to sign data, but it's not possible to export private key as string and it's really correct, only token owner should sign documents When you work with hardware token you can find private key as RSA KEY and sign data with it.
Rsa.ir (ره آورد سامانه های امن)
این سازمان به عنوان ارایه دهنده توکن های سخت افزاری حجم زیادی از توکن ها را در اختیار صاحبان کسب و کار قرار داده است نمونه کد های ارایه شدن به عنوان مشخصات فنی فاقد نمونه کد مناسب برای زبان سی شارپ می باشد
سامانه مودیان
از این کد در امضا درخواست ها برای سیستم ارایه شده توسط دارایی با عنوان سامانه مودیان استفاده شده است
Install
- Add nuget packge
dotnet add package TICS.Pks11
Usage
Dependency Injection Configuration (optional)
services.AddSingleton(new TokenCertificateOptions { FactoryType = config.FactoryType, RootDirectory = rootDirectory, StoreTokenLabel = config.StoreTokenLabel, TokenLabel = config.TokenLabel, TokenPinCode = config.TokenPinCode, PrivateKey = config.PrivateKey });
Get RSA Private Key to sign
TICS.Pks11.Pks11 pks = new TICS.Pks11.Pks11(_options);
var rsaPrivateKey = pks.GetPrivateKey();
Sign sample (کلاس مورد نیاز برای سامانه مودیان)
public class CustomSign : ISignatory
{
private TICS.Pks11.TokenCertificateOptions _options;
public CustomSign(TICS.Pks11.TokenCertificateOptions options)
{
_options = options;
}
public string GetKeyId()
{
return null;
}
public string Sign(string data)
{
TICS.Pks11.Pks11 pks = new TICS.Pks11.Pks11(_options);
var rsaPrivateKey = pks.GetPrivateKey();
if (rsaPrivateKey != null)
{
var dataBytes = Encoding.UTF8.GetBytes(data);
var signString = Convert.ToBase64String(rsaPrivateKey.SignData(dataBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));
return signString;
}
else return string.Empty;
}
}
TokenCertificateOptions
public class TokenCertificateOptions
{
public FactoryType FactoryType { get; set; }
public string RootDirectory { get; set; } = default!;
public string StoreTokenLabel { get; set; } = default!;
public string TokenLabel { get; set; } = default!;
public string TokenPinCode { get; set; } = default!;
public string PrivateKey { get; set; } = default!;
}
- RootDirectory: path to your dll file
- StoreTokenLabel: When factory type is 1 or 2 Name of token label (sample: ePass3003Auto), you can find this name on root of your hardware token
- TokenLabel: When factory type is 1 or 2 Name of token label (sample: ePass3003Auto), lable of token in Hardware token, each token can contains more than one token (sample: Amir Fahmideh [stamp])
- TokenLabel: When factory type is 1 or 2 pin code of token
- PrivateKey: only fill this property when use factory type 3
Factory Type
public enum FactoryType
{
PrivateKeyFile = 0,
EPass3003AutoX64 = 1,
EPass3003AutoX86 = 2,
PrivateKeyString = 3
}
- PrivateKeyFile: Use this type when you have privateKey.pem next to your root direcotry
- EPass3003AutoX64: Use this type when you want to have sign with private key in x64
- EPass3003AutoX86: Use this type when you want to have sign with private key in x86
- PrivateKeyString: Use this type when private key fild is not empty in your injected configurations setting
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
-
net7.0
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Pkcs11Interop (>= 5.1.2)
- Pkcs11Interop.X509Store (>= 0.4.0)
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.0.0 | 254 | 2/22/2023 |