Using Delphi with CryptoSys API, CryptoSys PKI
and FirmaSAT
It is possible to call all the functions in our cryptographic products CryptoSys API, CryptoSys PKI and FirmaSAT from Delphi. This page explains what we know and gives some sample code.
FirmaSAT |
CryptoSys API |
CryptoSys PKI Toolkit |
Notes for programmers |
Acknowledgements |
Disclaimer |
Contact |
Comments |
Español
The Delphi code on this page works for us using Delphi Builder 2010 on a Windows XP machine. There may well be better or more elegant ways of calling the functions. We don't know how backwards compatible this code is. We'll keep updating the code on this page as we refine things and get feedback (well, at least until our 30-day trial period ends :-).
If anyone has any corrections or useful suggestions, we'd be delighted to hear from you. Please contact us or add a comment using the links at the bottom of this page. For more info on creating interfaces see Writing an interface in another programming language.
Here is a full Delphi interface to all the functions in FirmaSAT including a series of tests and some test files: diFirmaSat.pas.zip (16 kB. Last updated 2010-03-18). The Delphi interfaces to the FirmaSAT functions are provided in the file diFirmaSat.pas. (Use at your own risk. No warranties, etc. See the Disclaimer below.)
You need to have installed both FirmaSAT and the CryptoSys PKI Toolkit on your system. For more information see How to get started on the FirmaSAT page.
Note that the tests in TestFirmaSat require certain files to exist in a specified directory. The test files are provided in the zip file above. The directory is hardcoded in the code
const
TEST_DIR = 'C:\Test\Muestra';
- you may need to edit this to suit your system.
For more information on the FirmaSAT function parameters and return values, see the C include file diFirmaSAT2.h.
Here is a Delphi interface to all the functions in CryptoSys API with a start on some typical tests: diCryptoSys.pas.zip (11 kB. Last updated 2010-03-18). The function declarations and associated constants are in the file diCryptoSys.pas.
For more information on the CryptoSys API function parameters and return values, see the Main manual for CryptoSys API.
Here is a provisional Delphi interface to all the functions in CryptoSys PKI with a few sample tests: diCrPKI.pas.zip (7 kB. Last updated 2010-03-17). The function declarations and associated constants are in the file diCrPKI.pas.
For more information on the CryptoSys PKI function parameters and return values, see the Main manual for CryptoSys PKI.
Variable types used in the interface:
| C++ Type | Delphi Type | Description |
|---|---|---|
long, int | Integer | A signed 32-bit integer, passed by value |
char *sz | AnsiString | ANSI string: a string of single-byte non-zero characters terminated by a zero byte |
unsigned char *lp | Array of Byte | Byte array: an ordered sequence of single-byte values of any value in the range [0,255] |
Integer, a 32-bit signed integer.AnsiString.
Attempting to pass a "normal" Unicode or Wide string will not work.Array of Byte.
buf : AnsiString;
//...
buf := AnsiString(StringOfChar(#0,nchars));
ret := FOO_StringFunction(Pointer(buf), nchars, ...);
arrbytes : Array of Byte;
//...
SetLength(arrbytes, nbytes);
ret := FOO_ByteFunction(Pointer(arrbytes), nbytes, ...);
These output parameters are expected as PChar PAnsiChar and PByte respectively.
[PChar also seemed to work OK for us in early tests and the compiler didn't complain either].
AnsiString type.
Constant byte arrays passed as input still need to be passed as a pointer (AFAWK).
AnsiString or Array of Byte, use the Delphi NIL value, as in
nchars := SAT_CompileTime(NIL, 0);
abKey : Array of Byte; tag : Array[0..15] of Byte; //... ret := GCM_Encrypt(NIL, 0, @tag[0], Length(tag), NIL, 0, Pointer(abKey), Length(abKey),...);
SetLength operation
SetLength(abOut, Length(abIn));
_UpdateHex functions which are used as both input and to receive output,
need to be declared as global vars, not local.
Thanks to Sebastian Jäschke and Humberto Souza for their help in providing example Delphi interfaces to CryptoSys API, without which we would not have been able to get started, and to Cesar Ruiz for his feedback. Thanks, too, to Neil Moffatt for his excellent Delphi Basics site.
Our CryptoSys products are offered primarily with interfaces using the C/C++, C#, VB6/VBA and VB.NET languages. We don't offer to support any other interfaces or languages. We will try and help if we can. The code on this page is offered for free in good faith but may contain nuts and/or errors. Please make whatever checks you need to before purchase of the main product.
For more information, please Email Us. To comment on this page, see below.
This page first published 13 March 2010. Last updated 20 August 2010
Comments
5 comments so far