CNC-Program en-/decryption (C12)

1.1 IntroductionPAGEREF _Toc307300231 \h2

1.2 Use-Case 3

1.3 Shipped components 4

1.4 Examples 5

1.4.1 Visual Basic 6 5

1.4.2 Visual Basic .net 6

More:

button Introduction

button Use-Case

button Shipped components

button Examples


Introduction

Encoded Files

The NC-Kernel in version 2.60 (TwinCAT 2.11) has the feature to run encrypted NC-Programs. These files are detected by the extension .enc (Encrypted NC).

To execute an encrypted NC-program the CNC must know the password the program has been encrypted with. This password must be set to the CNC before program start by an ADS write request:

Name: password
IndexGroup: 0x22301
IndexOffset: 0x1a
Port: 552 (task SDA)


Use-Case

Use-Case diagram

q An NC program is encrypted with an individual password and saved as <file>.enc.

q The corresponding password is set to the CNC before program start.

q For diagnostic / display purposes the encrypted program could be displayed on the user interface if the used password is known.


Shipped components

TcISGEncryption.dll

This is a helper dll which wraps the methods to encode and decode a NC-Program.

Functions:
unsigned long encode_cnc_file (char *pIn, char *pOut, char *password);

unsigned long decode_cnc_file (unsigned char *pDest, char *pName, long offset, long length, char *password);

encode_cnc_file

char *pIn à Filename for inputfile

char *pOut à Filename for outputfile

char *password à Password for encryption

decode_cnc_file

unsigned char *pDest à Buffer for output

char *pName à Filename for input

long offset à Offset for reading inside the inputfile

long length à Length of reading

char *password à Password for decryption


Examples

Examples

Additionally there were two examples. One for VB6 and another for VB.net.
Both were a short demonstration for using the TCISGEncryption.dll.

More:

button Visual Basic 6

button Visual Basic .net


Visual Basic 6

Description

This is a short example application to demonstrate how to enconde and decode a NC-Program.
The Start-Button starts the program in the text box.
The Stop-Button stops it.
With the Encode a file button you can encode an NC-Program.
The button activate decode switches the online decoding for the running program.

Programming example

Screenshot

Code Example

The following lines show the usage of the TcISGEncryption.dll with VB6:

Private Declare Function encode_cnc_file Lib "TcISGEncrypt.dll" _
(ByVal pIn As String, ByVal pOut As String, ByVal password As
String) As Long

Private Declare Function decode_cnc_file Lib "TcISGEncrypt.dll" _
(ByVal pDest As String, ByVal pName As String, ByVal Offset
As Long, ByVal length As Long, ByVal password As String) As
Long

----------------------------------------------------------------------

Dim fileIn As String
Dim fileOut As String
Dim password As String

encode_cnc_file(fileIn, fileOut, password)

----------------------------------------------------------------------

Dim Offset As Long
Dim dest As String * 10
DimpasswordAs String
Dimactive_file_nameAs String

Call decode_cnc_file(dest, active_file_name, Offset, Len(dest), password)


Visual Basic .net

Discription

In VB.net the program works in the same way like in VB6. For details please look at the description above.
A small difference is in the usage of the decoding function. To get the decoded program part you have to use a StringBuilder instead of a String. Otherwise the dll is not able to write into the buffer.

Programming example

Screenshot

Code Example

The following lines show the usage of the TcISGEncryption.dll with VB.net:

<DllImport("TcISGEncrypt.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function encode_cnc_file(ByVal pIn AsString, ByVal pOut AsString, ByVal password AsString) AsInteger

End Function

<DllImport("TcISGEncrypt.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function decode_cnc_file(ByVal pDest As StringBuilder, ByVal pName AsString, ByVal Offset AsInteger, ByVal length AsInteger, ByVal password AsString) AsInteger

End Function

----------------------------------------------------------------------

Dim fileIn As String
Dim fileOut As String
Dim password As String

encode_cnc_file(fileIn, fileOut, password)

----------------------------------------------------------------------

Dim Offset AsInteger
DimpasswordAs String
Dimactive_file_nameAs String
Dim dest = New StringBuilder
dest.Length = 10

decode_cnc_file(dest, active_file_name, Offset, 10, password)