Function Reference


_Crypt_DeriveKey

Creates a key from algorithm and password

#include <Crypt.au3>
_Crypt_DeriveKey ( $vPassword, $iAlgID [, $iHashPasswordID = $CALG_MD5] )

Parameters

$vPassword Password to use
$iAlgID Encryption ID of algorithm to be used with the key. See remarks.
$iHashPasswordID [optional] Id of the algo to hash the password with. See remarks.

Return Value

Success: a handle to a cryptographic key.
Failure: sets the @error flag to non-zero.
@error: 10+ - Failed to create hash object
20+ - Failed to hash password
30+ - Failed to generate key
1000+ - Failed to _Crypt_Startup()

Remarks

The key needs to be destroyed with _Crypt_DestroyKey().

    Encryption Algorithm ID

$iAlgID Value Type Key-length
$CALG_AES_128 0x0000660e Cipher block chaining 128 bits
$CALG_AES_192 0x0000660f Cipher block chaining 192 bits
$CALG_AES_256 0x00006610 Cipher block chaining 256 bits
$CALG_DES 0x00006601 Cipher block chaining 56 bits
$CALG_3DES 0x00006603 Cipher block chaining 168 bits
$CALG_RC2 0x00006602 Block encryption algorithm 128 bits
$CALG_RC4 0x00006801 Stream encryption algorithm 128 bits
$CALG_USERKEY 0

    Hashing Algorithm ID

$iHashPasswordID Value Type Key-length
$CALG_MD2 0x00008001 Hashing algorithm 128-bit
$CALG_MD4 0x00008002 Hashing algorithm 128-bit
$CALG_MD5 0x00008003 Hashing algorithm 128-bit
$CALG_SHA1 0x00008004 Hashing algorithm 160-bit
$CALG_SHA_256 0x0000800c Hashing algorithm 256-bit
$CALG_SHA_384 0x0000800d Hashing algorithm 384-bit
$CALG_SHA_512 0x0000800e Hashing algorithm 512-bit

Related

_Crypt_DecryptData, _Crypt_DecryptFile, _Crypt_DestroyKey, _Crypt_EncryptData, _Crypt_EncryptFile

See Also

Search CryptDeriveKey in MSDN Library.

Example

#include <Crypt.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
        Local $aStringsToEncrypt[6] = ["AutoIt", "SciTE", "Crypt", ".au3", 42, "42"]
        Local $sOutput = ""

        Local $hKey = _Crypt_DeriveKey("CryptPassword", $CALG_RC4) ; Declare a password string and algorithm to create a cryptographic key.

        For $vText In $aStringsToEncrypt
                $sOutput &= $vText & @TAB & " = " & _Crypt_EncryptData($vText, $hKey, $CALG_USERKEY) & @CRLF ; Encrypt the text with the cryptographic key.
        Next

        MsgBox($MB_SYSTEMMODAL, "Encrypted data", $sOutput)

        _Crypt_DestroyKey($hKey) ; Destroy the cryptographic key.
EndFunc   ;==>Example