TKeyGenParams passing Key as Empty

Post here messages if you have any problems with working of Enigma Protector
Riski1588
Posts: 13
Joined: Wed Aug 22, 2018 10:54 am

TKeyGenParams passing Key as Empty

Post by Riski1588 »

Hi,

I'm trying to integrate a key generator inside my application but it appears as though I keep getting EP_ERROR_KEYBUFFEREMPTY error code.

I have included Enigma_KeyGen_IDEA64.cs inside my application, and copied keygen64.dll to my build directory and included in my project build. The code I have for TKeyGenParams is

Code: Select all

            var regName = "Test User";
            var buffer = new string('\0', 2048);
            
            var key = new Enigma_KeyGen_IDE64.TKeyGenParams()
            {
                // Encryption data
                PrivateKey = "", // removed
                PublicKey = "", // removed
                EncryptedConstant = 0, // removed
                EncryptedSections = new bool[] { false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false },

                // Expiration
                UseKeyExpiration = true,
                ExpirationDay = 28,
                ExpirationMonth = 11,
                ExpirationYear = 2018,

                // Hardware ID
                HardwareID = "", // removed

                // Locking methods
                UseHardwareLocking = true,
                UseRegisterAfter = false,
                UseRegisterBefore = false,
                UseExecutionsLimit = false,
                UseDaysLimit = false,
                UseRunTimeLimit = false,
                UseGlobalTimeLimit = false,
                UseCountyLimit = false,

                // Key
                Key = buffer,
                KeyLen = buffer.Length,
                KeyBase = Enigma_KeyGen_IDE64.RB_64,
                KeyMode = Enigma_KeyGen_IDE64.RM_4096,
                KeyWithHyphens = false,

                // Registration Info
                RegInfo = regName,
                RegInfoLen = regName.Length
            };
Calling GenerateRegistrationKey as:

Code: Select all

            var encryptionResult = Enigma_KeyGen_IDE64.KG_GenerateRegistrationKey(ref key);
encryptionResult is always Enigma_KeyGen_IDE64.EP_ERROR_KEYBUFFEREMPTY

I'm using C# 7.3 and also tried KG_GenerateRegistrationKeyA and KG_GenerateRegistrationKeyW (exits my application).

DLL Decl:

Code: Select all

    // Enigma keygen API
    [DllImport("Keygen/keygen64.dll")]
    public static extern uint KG_GenerateRegistrationKey(ref TKeyGenParams kg);
I have also tried

Code: Select all

            var keybuffer = new char[2048];
            keybuffer.Initialize();
            test.Key = keybuffer.ToString();
            test.KeyLen = keybuffer.Length;

And swapped out the Marshall types:

Code: Select all

UnmanagedType.LPWStr
UnmanagedType.LPStr
UnmanagedType.BStr
Any help?
Riski1588
Posts: 13
Joined: Wed Aug 22, 2018 10:54 am

Re: TKeyGenParams passing Key as Empty

Post by Riski1588 »

Debugging native I get the following error:
Exception thrown at 0x0000000110003751 (keygen64.dll) in Test.exe: 0xC0000005: Access violation writing location 0x00000000D0F2985D.
I run the project as Administrator and still facing the same problem.

Steps to reproduce:
VS2017:
- New>Project>Windows Desktop>Console App (.NET Framework 4.6.1)
- Add 'Enigma_KeyGen_IDE64.cs' to project.
- Add 'keygen64.dll' to project.
- Change project platform target to x64.
- Add a TKeyGenParams using hardware locking and call KG_GenerateRegistrationKey
Enigma
Site Admin
Posts: 2939
Joined: Wed Aug 20, 2008 2:24 pm

Re: TKeyGenParams passing Key as Empty

Post by Enigma »

Hi,

Maybe the problem appears because you use Enigma_KeyGen_IDE instead of Enigma_KeyGen_IDE64?

Check attached project, I did the same as you described and it works well.
Attachments
ConsoleApp1.zip
(8.26 KiB) Downloaded 781 times
Riski1588
Posts: 13
Joined: Wed Aug 22, 2018 10:54 am

Re: TKeyGenParams passing Key as Empty

Post by Riski1588 »

Maybe the problem appears because you use Enigma_KeyGen_IDE instead of Enigma_KeyGen_IDE64?
How did you come to that conclusion considering my code examples? :)

This project doesn't work for me unless I change the project .NET framework to 3.5. Anything above that the console application crashes with no key being displayed.
Enigma
Site Admin
Posts: 2939
Joined: Wed Aug 20, 2008 2:24 pm

Re: TKeyGenParams passing Key as Empty

Post by Enigma »

Riski1588 wrote: Mon Dec 10, 2018 10:10 am How did you come to that conclusion considering my code examples?
Just a thoughts :)
Riski1588 wrote: Mon Dec 10, 2018 10:10 am This project doesn't work for me unless I change the project .NET framework to 3.5. Anything above that the console application crashes with no key being displayed
Can you please compile the exe from my above project and attach it here, so I can take a look?
Just curious, what is the problem there, is that an operating system, or compiled file?
Why it works for me and does not for you?
Enigma
Site Admin
Posts: 2939
Joined: Wed Aug 20, 2008 2:24 pm

Re: TKeyGenParams passing Key as Empty

Post by Enigma »

Re-tested it with Framework 4.6, no problems, works fine.
Riski1588
Posts: 13
Joined: Wed Aug 22, 2018 10:54 am

Re: TKeyGenParams passing Key as Empty

Post by Riski1588 »

I've attached the build that just exits.
Attachments
Debug.rar
(211.79 KiB) Downloaded 483 times
Riski1588
Posts: 13
Joined: Wed Aug 22, 2018 10:54 am

Re: TKeyGenParams passing Key as Empty

Post by Riski1588 »

Video showing the problem:
https://streamable.com/r3tff
Enigma
Site Admin
Posts: 2939
Joined: Wed Aug 20, 2008 2:24 pm

Re: TKeyGenParams passing Key as Empty

Post by Enigma »

You file works well on our test system, there is no any issue, key is well generated.
Can you please let me know Windows version you are testing?
Riski1588
Posts: 13
Joined: Wed Aug 22, 2018 10:54 am

Re: TKeyGenParams passing Key as Empty

Post by Riski1588 »

Windows 10 Enterprise
Version 1803 (OS Build 17134.407).
Post Reply