CryptoSys PKI Pro Manual

TDEA_B64Mode

Encrypts or decrypts data encoded in base64 using a specified mode. The key and initialization vector are required in base64.

VBA/VB6 Syntax

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

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

C/C++ Syntax

long __stdcall TDEA_B64Mode(char *szOutput, const char *szInput, const char *szKey, long fEncrypt, const char *szMode, const char *szIV);

Parameters

szOutput
[out] of sufficient length to receive the output.
szInput
[in] containing the input data in base64.
szKey
[in] containing the key in base64 format.
fEncrypt
[in] direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
szMode
[in] 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.
szIV
[in] containing the initialization vector (IV), if required, in base64 format.

Returns (VBA/C)

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

.NET Equivalent

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

Remarks

For ECB and CBC modes, the input string szInput must represent an exact multiple of eight bytes when decoded otherwise a "Data not a valid length" error will result. The key string szKey must represent exactly 24 bytes when decoded. The initialization vector string szIV must represent exactly 8 bytes when decoded unless szMode is ECB, in which case szIV is ignored (use ""). Valid base64 characters are [A-Za-z0-9+/] with '=' used as a padding character. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

Example

Examples in base64 are pretty obscure to read. This is the same example from TDEA_HexMode using base64 strings instead.

Dim nRet As Long
Dim sHexCorrect As String
Dim sHexInput As String
Dim sHexKey As String
Dim sHexInitV As String
Dim sOutput As String
Dim sInput As String
Dim sKey As String
Dim sInitV As String
Dim bEncrypt As Boolean
Dim sCorrect As String

' Start with input in hex
sHexInput = "5468697320736F6D652073616D706520636F6E74656E742E0808080808080808"
'            T h i s _ s o m e _ s a m p e _ c o n t e n t . (padding 8 x 08)
sHexKey = "737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32"
sHexInitV = "B36B6BFB6231084E"
sHexCorrect = "d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4"

' Convert to base64
sInput = cnvB64StrFromBytes(cnvBytesFromHexStr(sHexInput))
sKey = cnvB64StrFromBytes(cnvBytesFromHexStr(sHexKey))
sInitV = cnvB64StrFromBytes(cnvBytesFromHexStr(sHexInitV))
sCorrect = cnvB64StrFromBytes(cnvBytesFromHexStr(sHexCorrect))

' Set sOutput to be same length as sInput
sOutput = String(Len(sInput), " ")

Debug.Print "KY=" & sKey
Debug.Print "PT=" & sInput
Debug.Print "IV=" & sInitV
nRet = TDEA_B64Mode(sOutput, sInput, sKey, ENCRYPT, "CBC", sInitV)
Debug.Print "CT=" & sOutput & nRet
Debug.Print "OK=" & sCorrect

sInput = sOutput
nRet = TDEA_B64Mode(sOutput, sInput, sKey, DECRYPT, "CBC", sInitV)
Debug.Print "P'=" & sOutput & nRet

See Also

TDEA_BytesMode TDEA_HexMode

[Contents] [Index]

[PREV: SMIME_Wrap...]   [Contents]   [Index]   
   [NEXT: TDEA_BytesMode...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.