CryptoSys API Library Manual

TDEA_B64Mode

TDEA_B64Mode encrypts or decrypts data represented as a base64 string using a specified mode. The key and initialization vector are represented as base64 strings.

VB6/VBA Syntax

Public Declare Function TDEA_B64Mode Lib "diCryptoSys.dll" (ByVal strOutput As String, ByVal strInput As String, ByVal strKey As String, ByVal bEncrypt As Boolean, ByVal strMode As String, ByVal strIV As String) As Long

nRet = TDEA_B64Mode(strOutput, strInput, strKey, bEncrypt, strMode, strIV)

Parameters

strOutput
[out] String of sufficient length to receive the output.
strInput
[in] String containing the input data in base64.
strKey
[in] String containing the key in base64.
bEncrypt
[in] Boolean direction flag: set as True to encrypt or 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.
strIV
[in] String containing the initialization vector (IV), if required, in base64.

C/C++ Syntax

long _stdcall TDEA_B64Mode(char *strOutput, const char *strInput, const char *strKey, int bEncrypt, const char *strMode, const char *sIV);

Returns (VB6/C)

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

.NET Equivalent

Tdea.Encrypt Method (String, String, Mode, String, EncodingBase)
Tdea.Decrypt Method (String, String, Mode, String, EncodingBase)

Remarks

The length of the input string strInput must represent a multiple of the block size (8 bytes) when decoded. If not, an error will be returned. The initialization vector string strIV must represent exactly 8 bytes unless strMode is ECB, in which case strIV is ignored (use ""). The key strKey must represent exactly 24 bytes, the required key length. The output string strOutput must be set up with at least the same number of characters as the input string before calling. The variables strOutput and strInput should be different.

Example

Dim nRet As Long
Dim strOutput As String
Dim strInput As String
Dim strKey As String
Dim strIV As String
Dim bEncrypt As Boolean
Dim sCorrect As String

' Key is 0x737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32
strKey = "c3x5HyXq0OBGKSVDUvfcYpHlyyaRetoy"
' IV is 0xB36B6BFB6231084E
strIV = "s2tr+2IxCE4="
' 0x5468697320736F6D652073616D706520636F6E74656E742E0808080808080808
'  "T h i s _ s o m e _ s a m p e _ c o n t e n t ." (padding 8 x 08)
strInput = "VGhpcyBzb21lIHNhbXBlIGNvbnRlbnQuCAgICAgICAg="
sCorrect = "12/RF4+9AvhCMfXB0qL3SkFZSClk9nUkglQiPa+a+OQ="

' Set strOutput to be same length as strInput
strOutput = String(Len(strInput), " ")

Debug.Print "KY="; strKey
Debug.Print "IV="; strIV
Debug.Print "PT="; strInput
nRet = TDEA_B64Mode(strOutput, strInput, strKey, ENCRYPT, "CBC", strIV)
Debug.Print "CT="; strOutput; nRet
Debug.Print "OK="; sCorrect

strInput = strOutput
nRet = TDEA_B64Mode(strOutput, strInput, strKey, DECRYPT, "CBC", strIV)
Debug.Print "P'="; strOutput; nRet

This should result in output as follows:

KY=c3x5HyXq0OBGKSVDUvfcYpHlyyaRetoy
IV=s2tr+2IxCE4=
PT=VGhpcyBzb21lIHNhbXBlIGNvbnRlbnQuCAgICAgICAg=
CT=12/RF4+9AvhCMfXB0qL3SkFZSClk9nUkglQiPa+a+OQ= 0 
OK=12/RF4+9AvhCMfXB0qL3SkFZSClk9nUkglQiPa+a+OQ=
P'=VGhpcyBzb21lIHNhbXBlIGNvbnRlbnQuCAgICAgICAg= 0 

See Also

TDEA_HexMode TDEA_BytesMode

[Contents] [Index]

[HOME]   [NEXT: TDEA_Bytes...]

Copyright © 2001-9 D.I. Management Services Pty Ltd. All rights reserved.