Example Code

Encryption / Decryption in LabWindows/CVI

Code and Documents

Attachment

Overview

This document describes how to use Win32 APIs to encrypt / decrypt some text. It is mainly based on examples found on msdn site, ported to CVI with a proper user interface to demonstrate their usage

 

Description

Text encryption can be made relying on resources offered by the operating system, specyfically the Cryptographic Service Provider (CSP) that can be installed together with the operating system.

Microft distributes CryptoAPI interface to the CSP which I rely on in this example. As far as a CSP is available on your system, you should be able to use its functions as demontrated in this sample application.

This service provider and the associated APIs permit to a programmer who is not an expert in the cryptographic process (as I actually am) to use the functions to add security to their applications.

 

This example is mainly intended as a proof-of-concept. Actual legislation in various countries imposes limits to the use and exportation of cryptographic functions: before including such functions in a public application, either a free or commercial one, it is better to study whether such inclusion is legal or not.

 

NOTE: In this other example I have used some hashing functions to demontrate how to treat passwords, which are the first and basic item when thinking to security. You may want to look at it if your goal is simply to store passwords on disk in a secure manner rather that encrypting text/data for further use.

 

Steps to Implement or Execute Code

The sample program is ready to go. It uses only standard functions included in the CVI installation. No additional tools are required to execute it.

The application is based on the Win32 Interface to the system APIs: it is well possible that it requires the Full Develpment System release of CVI to be executed. I have no Base package install available to test it against so I'm not sure, but I suppose cryptographic functions are not included in the base system.

 

When running the application:

  1. Press "Enum resources" button to locate and enumerate cryptographic resources available in the system
  2. Enter the text you want to encrypt or paste some text in  "Text to encrypt" box
  3. Choose an encryption algorithm
  4. Press "Encrypt" button: encrypted text will be written in the output box (NOTE: in case some NUL character is produced as the output of the encryption, the text box will not show the complete output text. Nevertheless, further decryption will take place based on "raw data" box which it present on the panel)
  5. Press "Decrypt" button to decrypt text and compare the output text with the original one

 

 

Requirements

Software

CVI Full Development System release 2012 or later with support for Win32 API installed.

No additional tools needed.

 

Hardware

No hardware is needed to run this example.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors