Jump to content

dll for encryption


Recommended Posts

Hello,

I'm Very new to the DLL concept.

I need to use a dll which is built by someone.

In that dll i'm going to utilise only 2 functions.

function prototype is

int EXPORT AES_set_encrypt_key(const unsigned char *userKey, const int bits,

AES_KEY *key);

void EXPORT AES_encrypt(const unsigned char *in, unsigned char *out,

const AES_KEY *key);

Already i've built an Vi in which the user can enter some fields and if he presses the save button, the values are stored in a file as such.

Now i want to encrypt the data entered by the user and store the encrypted data into the file.

For the Encryption part a dll has been created.This dll will have 4 functions 2 for encrypting and 2 for decrypting.

Encrption should be taken care by LAbview part and Decryption by our software by C.

As my deadline is very near i cudn't go through the Pdf.

I'm confused with the CIN and Call library funtion.

Pls guide me in this regard.

Thanks and regards

SupriyaV

Link to comment
Hello,

I'm Very new to the DLL concept.

I need to use a dll which is built by someone.

In that dll i'm going to utilise only 2 functions.

function prototype is

int EXPORT AES_set_encrypt_key(const unsigned char *userKey, const int bits,

AES_KEY *key);

void EXPORT AES_encrypt(const unsigned char *in, unsigned char *out,

const AES_KEY *key);

Already i've built an Vi in which the user can enter some fields and if he presses the save button, the values are stored in a file as such.

Now i want to encrypt the data entered by the user and store the encrypted data into the file.

For the Encryption part a dll has been created.This dll will have 4 functions 2 for encrypting and 2 for decrypting.

Encrption should be taken care by LAbview part and Decryption by our software by C.

As my deadline is very near i cudn't go through the Pdf.

I'm confused with the CIN and Call library funtion.

Pls guide me in this regard.

Thanks and regards

SupriyaV

The easist possibility would be to get the Crypto-G Toolkit from http://www.jyestudio.com/visecurity/cryptg.shtml. It's pricing is VERY reasonable and definitely cheaper than spending even one or two hours of your time. It contains functions for AES encryption and decryption. Since AES is a standard it should be not a problem that the encryption is done by a different library than the decryption.

If you still are here and want to persuade the DLL path, reading the online reference manual about External Code in LabVIEW is an absolute minimum to do to be successful here. And unless you have a sound understanding of C you really will have to go to www.ni.com and do a search on external code to get some good references about what to watch out for. Most of that information is not even LabVIEW specific, but without knowing quite a bit about pointers, datatypes etc. you simply can't hope to get something reliable, using the Call Library Node or Code Interface Node.

One obvious indication that you may miss some basic understanding about C is that you leave out some important information here. Without knowing about the type definition for AES_KEY, nobody can possibly give you a ready made example as to how to implement this in LabVIEW. On the other hand if you would know that, the solution most probably would have presented itself to you already without any extra help.

You definitely don't want to use a CIN here, believe me, since that will absolutely and without any way to avoid it require you to write C code, so look at the Call Library Node (CLN)! While your information is not really enough to tell you a step by step plan to go with the CLN, you will have to create two VIs with a CLN in there each.

Another bit of information that is absolutely not clear is the calling convention that might or might not be defined with the EXPORT keyword. It is probably stdcall but cdecl would be quite likely to if the DLL you try to call is designed for multiplatform use. Trying this one out however is quite easy. If you get it wrong you will immediately crash LabVIEW so restart and try again, switching the calling convention before running the VI.

What remains are the "(const) unsigned char *" types and the "AES_KEY *". The first is easy as it is just a C string pointer. So you will have to configure the corresponding CLN parameters to a String type, pass as C string pointer. For the input strings you will pass in the string as required by the function but for the output string you have to allocate the string, since this is a standard convention in C: the caller of a function has to allocate the memory for any parameter that function is supposed to write into. To allocate memory in LabVIEW is easiest by creating an array of unsigned 8 bit integers with the Initialize Array function, and since we need really a string here we convert it then to a string with the Byte Array to String function. How much of memory you have to allocate for the function not to crash is however function dependant and should be documented by the developer of that function (if it is not documented in any way you should kick the developer in his ###### if you get a chance).

For the AES_KEY * I can only make wild guesses. It is likely a pointer to a structure. What size this structure has is unknown. As long as that structure does not contain variable sized elements (strings and arrays) you can create an according LabVIEW cluster, and configure the CLN to use Adapt to Type for this parameter. There is a possibility that your cluster uses a certain byte alignment. This is maybe visible in the C header file for your DLL by some #pragma pack() statements but just as likely it might be something only known by the developer. LabVIEW always uses byte packed structures so you might have to experiment here.

But considering all this I really very much would recommend you to look at getting Crypto-G. It will give you a ready made solution and definitely cost you less unless you value your time absolutely nothing.

Rolf Kalbermatter

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.