CryptoSys PKI Pro Manual

PBE_ScryptHex

Derives a key of any length from a password using the SCRYPT algorithm with the salt and derived key encoded in hexadecimal.

VBA/VB6 Syntax

Public Declare Function PBE_ScryptHex Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nMaxChars As Long, ByVal dkBytes As Long, ByVal strPwd As String, ByVal strSaltHex As String, ByVal nParamN As Long, ByVal nParamR As Long, ByVal nParamP As Long, ByVal nOptions As Long) As Long

nRet = PBE_ScryptHex(strDerivedKey, nMaxChars, dkBytes, strPassword, strSaltHex, nParamN, nParamR, nParamP, nOptions)

C/C++ Syntax

long __stdcall PBE_ScryptHex(char *szOutput, long nMaxChars, long dkBytes, const char *szPwd, const char *szSaltHex, long nParamN, long nParamR, long nParamP, long nOptions);

Parameters

szOutput
[out] to receive the hexadecimal-encoded derived key.
nMaxChars
[in] specifying the maximum number of characters in szOutput.
dkBytes
[in] specifying the size of the required key in bytes.
szPwd
[in] containing the password (as normal text).
szSaltHex
[in] containing the salt in hex format.
nParamN
[in] CPU/Memory cost parameter N ("costParameter") a number greater than one and a power of 2.
nParamR
[in] Block size r ("blockSize")
nParamP
[in] Parallelization parameter p ("parallelizationParameter")
nOptions
[in] Option flags: not used in this release. Specify zero.

Returns (VBA/C)

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

VBA Wrapper Syntax

Public Function pbeScryptHex (dkBytes As Long, szPwd As String, szSaltHex As String, nParamN As Long, nParamR As Long, nParamP As Long, Optional nOptions As Long = 0) As String

.NET Equivalent

Pbe.Scrypt Method (Int32, String, String, Int32, Int32, Int32)

Remarks

The output string szOutput should be pre-dimensioned to be at least double the required key length in bytes. (Hint: specify nMaxChars as Len(strOutput)). The seed szSaltHex is specified in hex format and can be any even number of hex digits in length. The password szPassword is normal text, not hexadecimal.

Example (VBA core function)

Dim strDerivedKey As String
Dim nKeyLen As Long
Dim strPassword As String
Dim strSaltHex As String
Dim nRet As Long

strPassword = "pleaseletmein"  ' NB normal text, not hex
strSaltHex = cnvHexStrFromString("SodiumChloride")

' Pre-dimension output string for derived key to
' required length of two times number of bytes
' (Don't forget to do this)
nKeyLen = 64
strDerivedKey = String(2 * nKeyLen, " ")

' Derive key using SCRYPT
nRet = PBE_ScryptHex(strDerivedKey, Len(strDerivedKey), nKeyLen, _
    strPassword, strSaltHex, 16384, 8, 1, 0)

Debug.Print "Derived key = " & strDerivedKey

This should result in output as follows:

Derived key = 7023BDCB3AFD7348461C06CD81FD38EBFDA8FBBA904F8E3EA9B543F6545DA1F2
D5432955613F0FCF62D49705242A9AF9E61E85DC0D651E40DFCF017B45575887

Example (VBA wrapper function)

Dim strDerivedKey As String
strDerivedKey = pbeScryptHex(64, "pleaseletmein", cnvHexStrFromString("SodiumChloride"), 16384, 8, 1, 0)
Debug.Print "Derived key = " & strDerivedKey
Debug.Print "OK =          " & "7023BDCB3AFD7348461C06CD81FD38EBFDA8FBBA904F8E3EA9B543F6545DA1F2D5432955613F0FCF62D49705242A9AF9E61E85DC0D651E40DFCF017B45575887"

See Also

PBE_Scrypt

[Contents] [Index]

[PREV: PBE_Scrypt...]   [Contents]   [Index]   
   [NEXT: PEM_FileFromBinFile...]

Copyright © 2004-23 D.I. Management Services Pty Ltd. All rights reserved. Generated 2023-10-22T11:11:11Z.