license problem

7/20/2017 9:06:27 PM
kkc
Gravatar
Total Posts 13

license problem

Hi Ugo,

I follow your license installation, and add Cryptoki.Licensee = "Licensee"; Cryptoki.ProductKey = "ProductKey" to my application. When I test it in your VB sample code,it's working, but if I add these code to my Console Application it's not working and alway notice"This version of NCryptoki is not licensed". What is the problem here?

7/20/2017 9:57:09 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: license problem

You should set the license codes once at the beginning of your program and that's all

7/21/2017 4:21:56 PM
kkc
Gravatar
Total Posts 13

Re: license problem

Hi Ugo,

I set the license codes once at the beginning of my program, and my code as follows:

 

Public Class MainForm


    Dim tokenslots As SlotList
    Dim token As Token
    Dim session As Session
    Dim Cryptoki = New Cryptoki("c:\Program Files\SafeNet\LunaClient\cryptoki.dll")
    Dim res As Integer


    Dim pgp As String = ""
    Dim strSource As String = ""
    Dim strLog As String = "Application"
    Dim strMachine As String = "."
    Public myEventLog As EventLog = New EventLog(strLog, strMachine, strSource)
    Public expiryDates As New Collection
    Public confFilePresent As Boolean = False


    Cryptoki.Licensee = "...my Licensee..."
    Cryptoki.ProductKey = "...my ProductKey"

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

these two lines
    Cryptoki.Licensee = "...my Licensee..."
    Cryptoki.ProductKey = "...my ProductKey"

show error on Cryptoki, and if I add these in the MainForm_Load, the error disappear but when I run the code, the notice"This version of NCryptoki is not licensed" is coming. What is the problem here? Thank you.

7/21/2017 5:33:10 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: license problem

Your code is wrong

You call:

Dim Cryptoki = New Cryptoki("c:\Program Files\SafeNet\LunaClient\cryptoki.dll")

and later 

Cryptoki.Licensee = "...my Licensee..."
Cryptoki.ProductKey = "...my ProductKey"

The license message appears when you call the first one

You must set the license before any instanciation of Cryptoki class, i.e. before:

Dim Cryptoki = New Cryptoki("c:\Program Files\SafeNet\LunaClient\cryptoki.dll")

7/24/2017 3:21:34 PM
kkc
Gravatar
Total Posts 13

Re: license problem

Hi Ugo,

I read your Cryptoki class, the instructor is

"  Public Sub New()    and  Public Sub New(cryptokilib As String)"

I have to set instanciation of Cryptoki class, then set the Licensee value. How can I set the license before any instanciation of Cryptoki class?

do you have any example code? Thank you.

namespace Cryptware.NCryptoki
   
    <ClassInterface(ClassInterfaceType.AutoDual)> <ComVisible(True)> <Guid("7EC26C78-4297-43e0-BDBC-5477362D8C53")>
    Public Class Cryptoki
        Implements ICryptoki

   
        Public Const CKF_DONT_BLOCK As Integer = 1
        Public Sub New()
        Public Sub New(cryptokilib As String)


        Public Shared Property Licensee As String  
        Public Shared Property ProductKey As String      
        Public ReadOnly Property ActiveSlots As SlotList 
        Public ReadOnly Property AttachedCryptokiLib As String   
        Public ReadOnly Property Info As CryptokiInfo  
        Public ReadOnly Property Slots As SlotList

7/24/2017 4:44:37 PM
kkc
Gravatar
Total Posts 13

Re: license problem

 Public Sub Main()

        Dim cryptoki As Cryptoki
        Dim tokenslots As SlotList
        Dim token As Token
        Dim session As Session
        Cryptoki.Licensee = "  "
        Cryptoki.ProductKey = "  "

        ' Creates a Cryptoki object related to the specific PKCS#11 native library
        cryptoki = New Cryptoki("c:\Program Files\SafeNet\LunaClient\cryptoki.dll")

        cryptoki.Initialize()

        'Prints all information relating to the native library

        ' Reads the set of slots containing a token
        tokenslots = cryptoki.ActiveSlots
        If (tokenslots.Count = 0) Then Throw New Exception("No token inserted")

        ' Gets the first token available
        token = tokenslots(0).Token

        ' Opens a read/write serial session
        session = token.OpenSession((Session.CKF_SERIAL_SESSION Or Session.CKF_RW_SESSION), Nothing, Nothing)

    End Sub 'Main

 

If I set these code under the  Public Sub Main(), it won't give me any error. If I set in the Public Class MainForm, the code won't working. But I have to set in the Public Class MainForm. What is the problem here?

 

7/25/2017 3:53:04 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: license problem

You should set the license in the Sub Main as you did:

Cryptoki.Licensee = "  "
Cryptoki.ProductKey = "  "

 

You can put the rest of the code where you want, in any function as you want.