CryptoSys API Library Manual

DES_CheckKey

Checks for weak or invalid-length DES or TDEA keys.

VBA/VB6 Syntax

Public Declare Function DES_CheckKey Lib "diCryptoSys.dll" (ByRef lpKey As Byte, ByVal nKeyBytes As Long) As Long

nRet = DES_CheckKey(abKey(0), nKeyBytes)

C/C++ Syntax

long __stdcall DES_CheckKey(const unsigned char *lpKey, long nKeyLen);

Parameters

lpKey
[in] array containing the key.
nKeyLen
[in] containing the length of the key in bytes.

Returns (VBA/C)

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

.NET Equivalent

Des.CheckKey Method (Byte[])
Tdea.CheckKey Method (Byte[])

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 abKey() As Byte
    Dim nKeyBytes As Long
    Dim nRet As Long
    
    nKeyBytes = 8
    ReDim abKey(nKeyBytes - 1)
    ' Generate a random DES key
    nRet = RNG_KeyBytes(abKey(0), nKeyBytes, "", 0)
    Debug.Print cnvHexStrFromBytes(abKey)
    ' Check if it's OK
    nRet = DES_CheckKey(abKey(0), nKeyBytes)
    Debug.Print "DES_CheckKey returns " & nRet & " (" & apiErrorLookup(nRet) & ")"
    If nRet <> 0 Then
        ' Error...
    End If

This should produce output similar to:

5305A0FA4CC94A82
DES_CheckKey returns 0 (OK, success, no error)

unless the key generated is weak (a 1 in 4500 billion chance!).

See Also

DES_CheckKeyHex

[Contents] [Index]

[PREV: DES_BytesMode...]   [Contents]   [Index]   
   [NEXT: DES_CheckKeyHex...]

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