Most of the functions in CryptoSys API have a `Bytes' and a `Hex' version.
The Bytes version expects its input as an array of bytes (unsigned char*
in C/C++)
together with another variable that specifies the length.
The Hex version expects its input as a hexadecimal-encoded string consisting only of the characters [0-9A-Fa-f]
where two hex characters represent an 8-bit byte.
In all these cryptographic algorithms, the underlying operations are carried out on 8-bit bytes (sometimes referred to as octets). See Storing and representing ciphertext.
In practice, especially with VB and VBScript, you may find it more convenient to use the 'Hex' versions and pass all your data to the API functions as hexadecimal-encoded strings.
Use the CNV_BytesFromHexStr
and CNV_HexStrFromBytes
functions to
convert between bytes and hexadecimal strings.
Use the Visual Basic StrConv
function to convert between a String
and an array of Byte
values.
See Converting strings to bytes and vice versa.
Note that the CNV_BytesFromHexStr
function will - by design - filter invalid hex characters
and return the resulting bytes from whatever is left without error.
The hex versions of the encryption functions are stricter
and will fail if any invalid hex characters are found in the input.
If your input data is in Unicode or UTF-16 format (e.g. your operating system is set up for CJK characters),
then you are strongly recommended to convert your input data to unambiguous hexadecimal format before trying to
use the functions in this API.
Do not try and use the Visual Basic String
type or it will end in tears.
For various historical reasons the Hex encryption functions return their results in upper case and
the hash digest functions in lower case.
Just be careful if you use the case-sensitive strcmp()
function in the C string.h
library
or if your Visual Basic options are set to Option Compare Binary
.
It's your decision which way you do it, but please be consistent.