The name 'Settings' does not exist in the current context

770 views
Skip to first unread message

busodan...@gmail.com

unread,
Aug 23, 2015, 1:29:43 PM8/23/15
to Pkcs11Interop
Hello, this is my first try with C#, I'm trying to use the "Pkcs11Interop" library with an example code ("_20_SignAndVerifyTest.cs"). But i can't figure how to make it work because it gives me these two errors "The name 'Settings' does not exist in the current context" and "The name 'Helpers' does not exist in the current context".

Thanks in advance for the help :)

busodan...@gmail.com

unread,
Aug 24, 2015, 11:09:33 AM8/24/15
to Pkcs11Interop, busodan...@gmail.com
Ok, i can't figure out how to use the library. I've also tryed to put all necessary files ("Settings.cs" and "Helper.cs" with the required folders) but nothing to do, errors disappeared but when i try to compile it give me another error (Something that has to do with symbols).

It would be fantastic if someone can tell me how to start with this library.

Thanks :)

Jaroslav Imrich

unread,
Aug 24, 2015, 6:31:03 PM8/24/15
to pkcs11...@googlegroups.com, busodan...@gmail.com
Hello Daniele,

if this is your first try with C# then I believe your best shot is to take a look at our standalone sample command line application called Pkcs7SignatureGenerator [0]. It can create PKCS#7 signature of any file stored on your computer. And of course you need to learn C# and get familiar with Visual Studio and other key components of .NET ecosystem.

Regards, Jaroslav

--
You received this message because you are subscribed to the Google Groups "Pkcs11Interop" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pkcs11intero...@googlegroups.com.
To post to this group, send email to pkcs11...@googlegroups.com.
Visit this group at http://groups.google.com/group/pkcs11interop.

busodan...@gmail.com

unread,
Aug 24, 2015, 6:46:21 PM8/24/15
to Pkcs11Interop
Thank you very much for the answer, and yes, this is my first try with C#.. I'm gonna look for that link tomorrow, i'll hope that it will help me understanding how C# works.. Up to now I have been working only with php (and similars) so i'm not familiar with this kind of programming languages... Hopefully you'll help me beginning with them..
Thank you again..

busodan...@gmail.com

unread,
Aug 25, 2015, 9:33:00 AM8/25/15
to Pkcs11Interop, busodan...@gmail.com
Ok I've looked at that example app but it doesn't work for me. I've opened the project in Xamarin and tried executing it with these parameters '--pkcs11-library "/usr/lib/opensc-pkcs11.so" --list-tokens' but i can't see any of my readers in the list (I'm working on OS X and with that library Firefox can see all my readers).

Where am I doing wrong? Thanks for the help anyway :)

busodan...@gmail.com

unread,
Aug 25, 2015, 2:32:22 PM8/25/15
to Pkcs11Interop, busodan...@gmail.com
Ok it was the wrong library.. However a question, with the "pkcs11interop" library am i able to sign on the card (so the private key stay inside the card)?

Jaroslav Imrich

unread,
Aug 25, 2015, 3:32:23 PM8/25/15
to pkcs11...@googlegroups.com, Daniele Buso
On Tue, Aug 25, 2015 at 8:32 PM, <busodan...@gmail.com> wrote:
Ok it was the wrong library.. However a question, with the "pkcs11interop" library am i able to sign on the card (so the private key stay inside the card)?

Yes - if that is what your PKCS#11 library does. It is important to understand that Pkcs11Interop is just a wrapper which calls functions exported by PKCS#11 library provided by your smartcard vendor. So if your PKCS#11 library performs signing inside the card then Pkcs11Interop does exactly the same thing.
 
Regards, Jaroslav

busodan...@gmail.com

unread,
Aug 27, 2015, 6:57:32 AM8/27/15
to Pkcs11Interop, busodan...@gmail.com
Ok, finally I have been able to make my first c# application, it read a cert from a smart card and then it sign a token, it works perfectly, however sometimes when i start the app it give me this error "CKR_DEVICE_ERROR" but can't understand why because if i restart the app it works. How can i solve/ avoid that?

Thanks, Regards, Daniele

busodan...@gmail.com

unread,
Aug 27, 2015, 8:38:22 AM8/27/15
to Pkcs11Interop, busodan...@gmail.com
If i try doing something like this:

bool done = false;

while (!done) {

try {

// Init session object
session = slot.OpenSession (false);

// Session Login
CKU userType = CKU.CKU_USER;
session.Login (userType, _cardPin);

} catch (Net.Pkcs11Interop.Common.Pkcs11Exception e) {

if (e.RV != CKR.CKR_DEVICE_ERROR) {
return false;
}

ui.Debug ("Error accessing token, trying again...");

} finally {

ui.Debug ("Access done...");
done = true;

}

}

Then I get this error "CKR_SESSION_HANDLE_INVALID" when it give the "Error accessing token, trying again..." debug message

Jaroslav Imrich

unread,
Aug 27, 2015, 5:31:55 PM8/27/15
to pkcs11...@googlegroups.com, Daniele Buso
Hello Daniele,


Ok, finally I have been able to make my first c# application, it read a cert from a smart card and then it sign a token, it works perfectly,

Good job!

 
however  sometimes when i start the app it give me this error "CKR_DEVICE_ERROR" but can't understand why because if i restart the app it works. How can i solve/ avoid that?

CKR_DEVICE_ERROR error is returned by PKCS#11 library provided by your smartcard vendor. You should consult documentation provided by the smartcard vendor or contact vendor support to resolve the error. BTW most PKCS#11 libraries support some kind of logging mechanism and when enabled logs can reveal more detailed information about the error than generic CKR_DEVICE_ERROR code does. Exact steps needed to enable logging should also be documented in the documentation provided by the smartcard vendor.


If i try doing something like this:

bool done = false;

                        while (!done) {

                                try {

                                        // Init session object
                                        session = slot.OpenSession (false);

                                        // Session Login
                                        CKU userType = CKU.CKU_USER;
                                        session.Login (userType, _cardPin);

                                } catch (Net.Pkcs11Interop.Common.Pkcs11Exception e) {

                                        if (e.RV != CKR.CKR_DEVICE_ERROR) {
                                                return false;
                                        }

While this may work I don't think this is a good idea. Errors should be resolved not hidden.


Regards, Jaroslav

busodan...@gmail.com

unread,
Aug 27, 2015, 6:01:18 PM8/27/15
to Pkcs11Interop, busodan...@gmail.com
Hello, thank you very much for your help, I'll surely check the documentation..
I will send you a mail about the flexible license, cause if what I'm trying to achieve works , I'll use that code in a commercial application..

Regards, Daniele Buso

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages