CryptoSys API Library Manual

BLF_B64Mode

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

VBA/VB6 Syntax

Public Declare Function BLF_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 = BLF_B64Mode(strOutput, strInput, strKey, bEncrypt, strMode, strIV)

C/C++ Syntax

long __stdcall BLF_B64Mode(char *szOutput, const char *szInput, const char *szKey, int 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.
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.

Returns (VBA/C)

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

.NET Equivalent

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

Remarks

The length of the input string szInput must represent a multiple of the block size (8 bytes) when decoded. If not, an error will be returned. The initialization vector string szIV must represent exactly 8 bytes unless szMode is ECB, in which case szIV is ignored (use ""). The key szKey can represent up to 56 bytes. 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

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

    ' "7654321 Now is the time for " padded to 32 bytes with 4 nulls
    strInput = "NzY1NDMyMSBOb3cgaXMgdGhlIHRpbWUgZm9yIAAAAAA="
    sCorrect = "a3e01jAG3uYFsVbidAOXk1jeuecVRhbZWfFlK9X/ksw="
    ' Key is 0x0123456789ABCDEFF0E1D2C3B4A59687
    strKey = "ASNFZ4mrze/w4dLDtKWWhw=="
    ' IV is 0xFEDCBA9876543210
    strIV = "/ty6mHZUMhA="
    ' Set strOutput to be same length as strInput
    strOutput = String(Len(strInput), " ")

    Debug.Print "KY=" & strKey
    Debug.Print "IV=" & strIV
    Debug.Print "PT=" & strInput
    ' Encrypt in one-off process
    nRet = BLF_B64Mode(strOutput, strInput, strKey, ENCRYPT, "CBC", strIV)
    Debug.Print "CT=" & strOutput, nRet
    Debug.Print "OK=" & sCorrect

    ' Now decrypt back to plain text
    strInput = strOutput
    nRet = BLF_B64Mode(strOutput, strInput, strKey, DECRYPT, "CBC", strIV)
    Debug.Print "P'=" & strOutput, nRet

This should result in output as follows:

KY=ASNFZ4mrze/w4dLDtKWWhw==
IV=/ty6mHZUMhA=
PT=NzY1NDMyMSBOb3cgaXMgdGhlIHRpbWUgZm9yIAAAAAA=
CT=a3e01jAG3uYFsVbidAOXk1jeuecVRhbZWfFlK9X/ksw=          0 
OK=a3e01jAG3uYFsVbidAOXk1jeuecVRhbZWfFlK9X/ksw=
P'=NzY1NDMyMSBOb3cgaXMgdGhlIHRpbWUgZm9yIAAAAAA=          0 

See Also

BLF_HexMode BLF_BytesMode

[Contents] [Index]

[PREV: API_Version...]   [Contents]   [Index]   
   [NEXT: BLF_Bytes...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.