Closed ozerkaya closed 5 years ago
This code won't work because when you construct X509Certificate2
this way it does not have any private key associated with it:
byte[] certData = objectAttributes[0].GetValueAsByteArray();
X509Certificate2 x509Certificate2 = new X509Certificate2(certData);
RSA rsaPrivateKey = x509Certificate2.GetRSAPrivateKey();
You can try to use Pkcs11Interop.X509Store library (that's where you opened this issue) and use GetRSAPrivateKey
method on Pkcs11X509Certificate
class instead.
@jariq thanks for reply. Yesterday all time I work for this issue but i cant take private key in usb hardware. I dont have a HSM. I have a usb hardware this is image: http://mm.kamusm.gov.tr/surecler/aldim_ne_yapmaliyim/1.jpg
I can not create PinProvider. Can you give a sample ? how can I use Pkcs11Interop.X509Store by new or external projects for private key ?
I can not create PinProvider. Can you give a sample?
You need to create your own class that implements IPinProvider
interface. Simplest example:
using Net.Pkcs11Interop.Common;
namespace ConsoleApp1
{
public class SimplePinProvider : IPinProvider
{
private byte[] _pin = null;
public SimplePinProvider(string pin)
{
_pin = ConvertUtils.Utf8StringToBytes(pin);
}
public GetPinResult GetKeyPin(Pkcs11X509StoreInfo storeInfo, Pkcs11SlotInfo slotInfo, Pkcs11TokenInfo tokenInfo, Pkcs11X509CertificateInfo certificateInfo)
{
return new GetPinResult(false, _pin);
}
public GetPinResult GetTokenPin(Pkcs11X509StoreInfo storeInfo, Pkcs11SlotInfo slotInfo, Pkcs11TokenInfo tokenInfo)
{
return new GetPinResult(false, _pin);
}
}
}
How can I use Pkcs11Interop.X509Store by new or external projects for private key?
By referencing Pkcs11Interop.X509Store
nuget package.
First of all, congratulations on sharing. very successful business. My problem is I can't get the private key.