Derives a key of any length from a password using the SCRYPT algorithm with the salt and derived key encoded in hexadecimal.
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)
long __stdcall PBE_ScryptHex(char *szOutput, long nMaxChars, long dkBytes, const char *szPwd, const char *szSaltHex, long nParamN, long nParamR, long nParamP, long nOptions);
"costParameter"
) a number greater than one and a power of 2."blockSize"
)"parallelizationParameter"
)If successful, the return value is 0; otherwise it returns a non-zero error code.
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
Pbe.Scrypt Method (Int32, String, String, Int32, Int32, Int32)
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.
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
Dim strDerivedKey As String
strDerivedKey = pbeScryptHex(64, "pleaseletmein", cnvHexStrFromString("SodiumChloride"), 16384, 8, 1, 0)
Debug.Print "Derived key = " & strDerivedKey
Debug.Print "OK = " & "7023BDCB3AFD7348461C06CD81FD38EBFDA8FBBA904F8E3EA9B543F6545DA1F2D5432955613F0FCF62D49705242A9AF9E61E85DC0D651E40DFCF017B45575887"