Opened on Oct 1, 2012 at 9:21:55 PM
Last modified on Jan 19, 2013 at 9:49:19 AM
#2263 closed Feature Request
Add CryptGenRandom Function to Crypt.au3 UDF — at Version 4
| Reported by: | wraithdu | Owned by: | |
|---|---|---|---|
| Milestone: | 3.3.9.5 | Component: | Standard UDFs |
| Version: | Severity: | None | |
| Keywords: | crypt udf cryptgenrandom | Cc: |
Description (last modified by )
Here's the function:
; #FUNCTION# ===================================================================
; Name...........: _Crypt_GenRandom
; Description ...: Fill a buffer with cryptographically random data.
; Syntax.........: _Crypt_GenRandom($pBuffer, $iSize)
; Parameters ....: $pBuffer - Pointer to buffer to fill with random data.
; $iSize - Size of the buffer pointed to by $pBuffer.
; Return values .: Success - Returns True
; Failure - Returns False and sets @error.
; Author ........: Erik Pilsits (wraithdu)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: @@MsdnLink@@ CryptGenRandom
; Example .......: Yes
; ==============================================================================
Func _Crypt_GenRandom($pBuffer, $iSize)
_Crypt_Startup()
Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptGenRandom", "handle", __Crypt_Context(), "dword", $iSize, "ptr", $pBuffer)
Local $nError = @error
_Crypt_Shutdown()
If $nError Or (Not $aRet[0]) Then
Return SetError(1, 0, False)
Else
Return True
EndIf
EndFunc ;==>_Crypt_GenRandom
Change History (4)
comment:1 by , on Oct 1, 2012 at 10:00:02 PM
| Version: | 3.3.9.4 |
|---|
comment:2 by , on Oct 1, 2012 at 11:04:13 PM
I goofed a parameter. The first parameter should be $pBuffer.
Also this should be added to the Remarks:
MSDN notes about the buffer: Optionally, the application can fill this buffer with data to use as an auxiliary random seed.
comment:3 by , on Oct 1, 2012 at 11:11:38 PM
Example:
#include <Crypt.au3>
; generate 16 bytes of random data
Local $buff = DllStructCreate("byte[16]")
_Crypt_GenRandom(DllStructGetPtr($buff), DllStructGetSize($buff))
MsgBox(0, "Random data:", DllStructGetData($buff, 1))
comment:4 by , on Oct 1, 2012 at 11:55:38 PM
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.

Automatic ticket cleanup.