Error 2147482748

11/1/2016 12:37:16 PM
Gravatar
Total Posts 6

Error 2147482748

Hi,

Sometimes we get error 2147482748. Is there any explanation about this error code ?

11/4/2016 2:03:05 PM
Gravatar
Total Posts 30

Re: Error 2147482748

Can you share the source code that gives such an error?

11/8/2016 8:26:44 AM
Gravatar
Total Posts 6

Re: Error 2147482748

Hi again,

Code is below, normally it works fine but in this specific project we get error. Same <span data-scayt_word="HSM" data-scaytid="28">HSM device (<span data-scayt_word="SafeNet" data-scaytid="33">SafeNet) running without any problem with other projects in production environment.

In Error stack trace displaying "Cryptware.NCryptoki.CryptokiException: Error n. -2147482748" but in code line it prints end of method (not right line btw)



                    <span data-scayt_word="CryptokiCollection" data-scaytid="1">CryptokiCollection template = new <span data-scayt_word="CryptokiCollection" data-scaytid="2">CryptokiCollection();
                    template.Add(new <span data-scayt_word="ObjectAttribute" data-scaytid="3">ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_SECRET_KEY));
                    template.Add(new <span data-scayt_word="ObjectAttribute" data-scaytid="4">ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, Key.CKK_AES));
                    template.Add(new <span data-scayt_word="ObjectAttribute" data-scaytid="5">ObjectAttribute(ObjectAttribute.CKA_LABEL, "<span data-scayt_word="KeyLabel1" data-scaytid="8">KeyLabel1"));

                    <span data-scayt_word="CryptokiCollection" data-scaytid="9">CryptokiCollection objects = session.Objects.Find(template, 1);

                    if (objects.Count == 0)
                    {
                        throw new Exception("No Key Found");
                    }

                    <span data-scayt_word="SecretKey" data-scaytid="13">SecretKey <span data-scayt_word="secretKey" data-scaytid="15">secretKey = (<span data-scayt_word="SecretKey" data-scaytid="14">SecretKey)objects[0];

                    byte[] text = Encoding.GetEncoding("Windows-1254").GetBytes(value);

                    session.EncryptInit(Mechanism.AES_CBC_PAD, <span data-scayt_word="secretKey" data-scaytid="16">secretKey);

                    byte[] <span data-scayt_word="encryptedText" data-scaytid="19">encryptedText = session.Encrypt(text);

                    string <span data-scayt_word="encryptedString" data-scaytid="22">encryptedString = Convert.ToBase64String(<span data-scayt_word="encryptedText" data-scaytid="21">encryptedText);
 

11/8/2016 8:31:44 AM
Gravatar
Total Posts 6

Re: Error 2147482748

By the way error code comes with prefix "-" like below

-2147482748

11/8/2016 9:50:31 AM
Gravatar
Total Posts 6

Re: Error 2147482748

I <span data-scayt_word="didnt" data-scaytid="1">didnt copy that, we create session at application begins and use this sessions with code in up.



        public <span data-scayt_word="BlockingCollection" data-scaytid="12">BlockingCollection<Session> Sessions { get; set; }

 

 


            Cryptoki.Licensee = SecurityConfiguration.NcryptokiLicensee;
            Cryptoki.ProductKey = SecurityConfiguration.NcryptokiProductKey;
            // <span data-scayt_word="TODO" data-scaytid="17">TODO : Get Active Slot Description From Singleton dapper repository. (<span data-scayt_word="HsmKeyInformation" data-scaytid="18">HsmKeyInformation)
            <span data-scayt_word="Cryptoki" data-scaytid="21">Cryptoki <span data-scayt_word="cryptoki" data-scaytid="23">cryptoki = new <span data-scayt_word="Cryptoki" data-scaytid="22">Cryptoki("cryptoki.dll");
            cryptoki.Initialize(true);
            <span data-scayt_word="CryptokiInfo" data-scaytid="25">CryptokiInfo info = cryptoki.Info;

            // Reads the set of slots containing a token
            <span data-scayt_word="SlotList" data-scaytid="27">SlotList slots = cryptoki.Slots;
            if (slots.Count == 0)
            {
                throw new Exception("No slot available");
            }

            <span data-scayt_word="int" data-scaytid="29">int <span data-scayt_word="slotId" data-scaytid="30">slotId = int.Parse(this.GetProtectedConfigValue("<span data-scayt_word="SlotId" data-scaytid="32">SlotId"));

            <span data-scayt_word="var" data-scaytid="33">var slot = slots.SingleOrDefault(x => x.SlotID == <span data-scayt_word="slotId" data-scaytid="31">slotId);
            if (slot == null)
                slot = slots[0];
            if (!slot.IsTokenPresent)
            {
                throw new Exception("No token inserted in the slot: " + slot.Info.Description);
            }

            <span data-scayt_word="var" data-scaytid="35">var token = slot.Token;


            string <span data-scayt_word="slotPassword" data-scaytid="37">slotPassword = this.GetProtectedConfigValue("<span data-scayt_word="SlotPassword" data-scaytid="38">SlotPassword");

            for (<span data-scayt_word="int" data-scaytid="39">int i = 0; i < 10; i++)
            {
                Session <span data-scayt_word="readonlySession" data-scaytid="41">readonlySession = token.OpenSession(Session.CKF_SERIAL_SESSION | Session.CKF_RW_SESSION,
                                      null,
                                      null);

                //this.currentSession = <span data-scayt_word="readonlySession" data-scaytid="42">readonlySession;
                <span data-scayt_word="int" data-scaytid="43">int <span data-scayt_word="nRes" data-scaytid="45">nRes = 0;

                if (!readonlySession.IsLoggedIn)
                {
                    <span data-scayt_word="nRes" data-scaytid="48">nRes = readonlySession.Login(Session.CKU_USER, <span data-scayt_word="slotPassword" data-scaytid="50">slotPassword);
                    if (<span data-scayt_word="nRes" data-scaytid="49">nRes != 0)
                    {
                        throw new Exception("Wrong PIN" + nRes.ToString());
                    }
                    Console.WriteLine("<span data-scayt_word="Sesssion" data-scaytid="54">Sesssion login success.");
                }
                else
                {
                    Console.WriteLine("<span data-scayt_word="Sesssion" data-scaytid="55">Sesssion already logged in.");
                }
                this.Sessions.Add(<span data-scayt_word="readonlySession" data-scaytid="58">readonlySession);
            }

11/8/2016 1:07:23 PM
Gravatar
Total Posts 6

Re: Error 2147482748

When reflected ncryptoki.dll i see this is defined as <span data-scayt_word="CKR_SMS_ERROR" data-scaytid="7">CKR_SMS_ERROR,

 

in <span data-scayt_word="SafeNet" data-scaytid="12">SafeNet documentation explanation is:

<span data-scayt_word="CKR_SMS_ERROR" data-scaytid="25">CKR_SMS_ERROR
<span data-scayt_word="0x80000384" data-scaytid="28">0x80000384
General error from secure messaging system – probably caused by <span data-scayt_word="HSM" data-scaytid="29">HSM failure or network failure.

11/14/2016 7:58:37 AM
Gravatar
Total Posts 6

Re: Error 2147482748

Any help ? We can't find why it gives error about this

11/14/2016 10:16:18 AM
Gravatar
Total Posts 30

Re: Error 2147482748

<span data-scayt_word="Th" data-scaytid="3">This error comes from <span data-scayt_word="SafeNet" data-scaytid="1">SafeNet <span data-scayt_word="HSM" data-scaytid="2">HSM.

It seems to be this one:

CKR_SMS_ERROR
0x80000384

I found also this document that speaks about that error at page 6:

http://www.securedbysafenet.com/<span data-scayt_word="releasenotes" data-scaytid="10">releasenotes/<span data-scayt_word="ptk" data-scaytid="11">ptk/crn_ptk_5-1.pdf

Finally it is a <span data-scayt_word="SafeNet" data-scaytid="8">SafeNet custom error.

Because <span data-scayt_word="NCryptoki" data-scaytid="13">NCryptoki is a wrapper around the <span data-scayt_word="PKCS" data-scaytid="14">PKCS#11 module, it works as a bridge between the native <span data-scayt_word="PKCS" data-scaytid="15">PKCS#11 <span data-scayt_word="dll" data-scaytid="16">dll and .NET application. It passes the .NET call to the underlying module, gets the error code from it and returns it to the .NET caller.

So we don't know why you are getting such an error. You should refer to the <span data-scayt_word="SafeNet" data-scaytid="9">SafeNet documentation to understand why