CryptoSys PKI Toolkit Manual

TDEA_File

TDEA_File encrypts or decrypts a file using a specified mode. The key and initialization vector are passed as arrays of bytes. PKCS-5/7 padding is used.

VB6/VBA Syntax

Public Declare Function TDEA_File Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByRef abKey As Byte, ByVal fEncrypt As Long, ByVal strMode As String, ByRef abInitV As Byte) As Long

nRet = TDEA_File(strFileOut, strFileIn, abKey(0), fEncrypt, strMode, abInitV(0))

Parameters

strFileOut
[in] String with the full path name of the output file to be created.
strFileIn
[in] String with the full path name of the input file to be processed.
abKey
[in] Byte array containing the key.
fEncrypt
[in] Boolean direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
strMode
[in] String specifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
abInitV
[in] Byte array containing the initialization vector (IV), or zero (0) for ECB mode.

C/C++ Syntax

long _stdcall TDEA_File(const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long fEncrypt, const char *szMode, const unsigned char *lpIV);

Returns (VB6/C)

Long: If successful, the return value is zero; otherwise it returns a nonzero error code.

.NET Equivalent

Tdea.FileEncrypt Method (String, String, Byte[], Mode, Byte[])
Tdea.FileDecrypt Method (String, String, Byte[], Mode, Byte[])

Remarks

The key array abKey() must be exactly 16 bytes long. The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0). The output file strFileOut will be overwritten without warning. If there is an error [new in version 3.1], the output file will not exist. The input and output files must not be the same. In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] section 10.3 and [PKCS5] section 6.1.1 and [RFC 1423] para 1.1.

Example

    Const MY_PATH As String = "C:\Test\"
    Dim aKey() As Byte
    Dim strFileOut As String
    Dim strFileIn As String
    Dim strFileChk As String
    Dim nRet As Long

    ' Construct full path names to files
    strFileIn = MY_PATH & "hello.txt"
    strFileOut = MY_PATH & "hello.tdea.enc.dat"
    strFileChk = MY_PATH & "hello.tdea.chk.txt"

    ' Create the key as an array of bytes
    ' This creates an array of 24 bytes {&HFE, &HDC, ... &H10}
    aKey = cnvBytesFromHexStr("fedcba9876543210fedcba9876543210fedcba9876543210")

    ' Encrypt plaintext file to ciphertext
    ' Output file = 16-byte ciphertext file hello.enc
    nRet = TDEA_File(strFileOut, strFileIn, aKey(0), ENCRYPT, "ECB", 0)
    Debug.Print nRet

    ' Now decrypt it
    nRet = TDEA_File(strFileChk, strFileOut, aKey(0), DECRYPT, "ECB", 0)
    Debug.Print nRet

See Also

TDEA_BytesMode

[Contents] [Index]

[HOME]   [NEXT: TDEA_HexMode...]

Copyright © 2004-10 D.I. Management Services Pty Ltd. All rights reserved.