CryptoSys API Library Manual

DES_CheckKeyHex

Checks for weak or invalid-length DES or TDEA keys in hexadecimal format.

VBA/VB6 Syntax

Public Declare Function DES_CheckKeyHex Lib "diCryptoSys.dll" (ByVal strHexKey As String) As Long

nRet = DES_CheckKeyHex(strHexKey)

C/C++ Syntax

long __stdcall DES_CheckKeyHex(const char *szHexKey);

Parameters

szHexKey
[in] containing the key in hexadecimal format.

Returns (VBA/C)

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

.NET Equivalent

Des.CheckKey Method (String)
Tdea.CheckKey Method (String)

Remarks

DES_CheckKey verifies that the key size is valid for a single, double or triple DES key - i.e. is 8, 16 or 24 bytes long - and that no part of the key is a weak or semi-weak DES key.

Example

    Dim nRet As Long
    Dim strKeyHex As String
    
    ' Weak key
    strKeyHex = "0101010101010101"
    nRet = DES_CheckKeyHex(strKeyHex)
    Debug.Print strKeyHex & " is " & IIf(nRet = 0, "OK", "BAD") & " (" & apiErrorLookup(nRet) & ")"

    ' Valid key by one bit
    strKeyHex = "0101010101010102"
    nRet = DES_CheckKeyHex(strKeyHex)
    Debug.Print strKeyHex & " is " & IIf(nRet = 0, "OK", "BAD") & " (" & apiErrorLookup(nRet) & ")"

    ' Another weak key
    strKeyHex = "01fe01fe01fe01fe"
    nRet = DES_CheckKeyHex(strKeyHex)
    Debug.Print strKeyHex & " is " & IIf(nRet = 0, "OK", "BAD") & " (" & apiErrorLookup(nRet) & ")"

    ' Weak double key in 1st half
    strKeyHex = "01010101010101010001112223334455"
    nRet = DES_CheckKeyHex(strKeyHex)
    Debug.Print strKeyHex & " is " & IIf(nRet = 0, "OK", "BAD") & " (" & apiErrorLookup(nRet) & ")"

    ' Weak triple key in 3rd part
    strKeyHex = "000111222333444555666777888999aa0101010101010101"
    nRet = DES_CheckKeyHex(strKeyHex)
    Debug.Print strKeyHex & " is " & IIf(nRet = 0, "OK", "BAD") & " (" & apiErrorLookup(nRet) & ")"

    ' Valid key
    strKeyHex = "000111222333444555666777888999aaabbbcccdddeeefff"
    nRet = DES_CheckKeyHex(strKeyHex)
    Debug.Print strKeyHex & " is " & IIf(nRet = 0, "OK", "BAD") & " (" & apiErrorLookup(nRet) & ")"

    ' Wrong key length (missing 'f' at end)
    strKeyHex = "000111222333444555666777888999aaabbbcccdddeeeff"
    nRet = DES_CheckKeyHex(strKeyHex)
    Debug.Print strKeyHex & " is " & IIf(nRet = 0, "OK", "BAD") & " (" & apiErrorLookup(nRet) & ")"

This should produce the output:

0101010101010101 is BAD (Weak key)
0101010101010102 is OK (OK, success, no error)
01fe01fe01fe01fe is BAD (Weak key)
01010101010101010001112223334455 is BAD (Weak key)
000111222333444555666777888999aa0101010101010101 is BAD (Weak key)
000111222333444555666777888999aaabbbcccdddeeefff is OK (OK, success, no error)
000111222333444555666777888999aaabbbcccdddeeeff is BAD (Invalid key length)

See Also

DES_CheckKey

[Contents] [Index]

[PREV: DES_CheckKey...]   [Contents]   [Index]   
   [NEXT: DES_File...]

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