Giter VIP home page Giter VIP logo

Comments (3)

jariq avatar jariq commented on June 3, 2024

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.

from pkcs11interop.x509store.

ozerkaya avatar ozerkaya commented on June 3, 2024

@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 ?

from pkcs11interop.x509store.

jariq avatar jariq commented on June 3, 2024

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.

from pkcs11interop.x509store.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.