Prng ActiveX Reference Documentation
Prng
Current Version: 10.1.2
Provides secure pseudo-random number generation (PRNG). Implements the Fortuna PRNG algorithm using 256-bit AES and SHA256. Also provides methods for accessing sources of system entropy.
Object Creation
Note: For versions of Chilkat < 10.0.0, use "Chilkat_9_5_0.Prng" instead of "Chilkat.Prng" For a specific major version, use "Chilkat.Prng.<major_version>", such as "Chilkat.Prng.10" for Chilkat v10.*.* See Chilkat ActiveX Object Creation (ASP) set obj = Server.CreateObject("Chilkat.Prng") (AutoIt) $obj = ObjCreate("Chilkat.Prng") (Visual Basic 6.0) Dim obj As New ChilkatPrng (VBScript) set obj = CreateObject("Chilkat.Prng") (Delphi) obj := TChilkatPrng.Create(Self); (FoxPro) loObject = CreateObject('Chilkat.Prng') (PowerBuilder) lole_object = create oleobject li_rc = lole_object.ConnectToNewObject("Chilkat.Prng") (SQL Server) EXEC @hr = sp_OACreate 'Chilkat.Prng', @obj OUT (Javascript) var obj = new ActiveXObject("Chilkat.Prng");
Properties
DebugLogFilePath
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
LastBinaryResult
This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. It is only accessible if Chilkat.Global.KeepBinaryResult is set to 1. This feature allows for the retrieval of large varbinary results in an SQL Server environment, which has restrictions on returning large data via method calls, though temp tables can handle binary properties.
topLastErrorHtml
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages.
topLastStringResult
In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. It is accessible only when Chilkat.Global.KeepStringResult is set to TRUE. SQL Server has limitations on string lengths returned from methods and properties, but temp tables can be used to access large strings.
LastStringResultLen
The length, in characters, of the string contained in the LastStringResult property.
topPrngName
The name of the PRNG selected. Currently, the default and only possible value is "fortuna". See the links below for information about the Fortuna PRNG.
Note: Because "fortuna" is the only valid choice, assigning this property to a different value will always be ignored (until alternative PRNG algorithms are added in the future).
VerboseLogging
If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
topVersion
Version of the component/library, such as "10.1.0"
Methods
AddEntropy
Adds entropy to the PRNG (i.e. adds more seed material to the PRNG). Entropy can be obtained by calling GetEntropy, or the application might have its own sources for obtaining entropy. An application may continue to add entropy at desired intervals. How the entropy is used depends on the PRNG algorithm. For Fortuna, the entropy is added to the internal entropy pools and used when internal automatic reseeding occurs.
An application may add non-random entropy for testing purposes. This allows for the reproduction of the same pseudo-random number sequence for testing and debugging purposes.
The entropy bytes are passed in entropy using the binary encoding specified in encoding. Binary encodings can be "hex", "base64", etc. See the link below for supported binary encodings.
Returns 1 for success, 0 for failure.
AddEntropyBytes
Adds entropy to the PRNG (i.e. adds more seed material to the PRNG). Entropy can be obtained by calling GetEntropy, or the application might have its own sources for obtaining entropy. An application may continue to add entropy at desired intervals. How the entropy is used depends on the PRNG algorithm. For Fortuna, the entropy is added to the internal entropy pools and used when internal automatic reseeding occurs.
An application may add non-random entropy for testing purposes. This allows for the reproduction of the same pseudo-random number sequence for testing and debugging purposes.
Returns 1 for success, 0 for failure.
topExportEntropy
Exports all accumulated entropy and returns it in a base64 encoded string. (Internally the entropy pools are re-hashed so that a hacker cannot determine the state of the PRNG even if the exported entropy was obtained.) When a system restarts it can import what was previously exported by calling ImportEntropy. This ensures an adequate amount of entropy is immediately available when first generating random bytes.
For example, an application could persist the exported entropy to a database or file. When the application starts again, it could import the persisted entropy, add some entropy from a system source (via the GetEntropy/AddEntropy methods), and then begin generating random data.
Returns Nothing on failure
FirebasePushId
Generates a random Firebase Push ID. See Firebase Unique Identifiers.
Returns Nothing on failure
GenRandom
Generates and returns numBytes random bytes in encoded string form. The binary encoding is specified by encoding, and can be "hex", "base64", etc. (See the link below for supported binary encodings.)
Important: If no entropy was explicitly added prior to first call to generate random bytes, then 32 bytes of entropy (from the system source, such as /dev/random) are automatically added to seed the PRNG.
Returns Nothing on failure
GenRandomBd
Appends numBytes random bytes to bd.
Important: If no entropy was explicitly added prior to first call to generate random bytes, then 32 bytes of entropy (from the system source, such as /dev/random) are automatically added to seed the PRNG.
Returns 1 for success, 0 for failure.
GenRandomBytes
Generates and returns numBytes random bytes.
Important: If no entropy was explicitly added prior to first call to generate random bytes, then 32 bytes of entropy (from the system source, such as /dev/random) are automatically added to seed the PRNG.
Returns a zero-length byte array (as a Variant) on failure.
An empty array will have a UBound of -1 meaning 0 elements.
GetEntropy
Reads real entropy bytes from a system entropy source and returns as an encoded string. On Linux/Unix based systems, including MAC OS X, this is accomplished by reading /dev/random. On Windows systems, it uses the Microsoft Cryptographic Service Provider's CryptGenRandom method.
It is recommended that no more than 32 bytes of entropy should be retrieved to initially seed a PRNG. Larger amounts of entropy are fairly useless. However, an app is free to periodically add bits of entropy to a long-running PRNG as it sees fit.
The encoding specifies the encoding to be used. It can be "hex", "base64", or many other possibilities. See the link below.
Returns Nothing on failure
GetEntropyBytes
Reads and returns real entropy bytes from a system entropy source. On Linux/Unix based systems, including MAC OS X, this is accomplished by reading /dev/random. On Windows systems, it uses the Microsoft Cryptographic Service Provider's CryptGenRandom method.
It is recommended that no more than 32 bytes of entropy should be retrieved to initially seed a PRNG. Larger amounts of entropy are fairly useless. However, an app is free to periodically add bits of entropy to a long-running PRNG as it sees fit.
Returns a zero-length byte array (as a Variant) on failure.
An empty array will have a UBound of -1 meaning 0 elements.
ImportEntropy
Imports entropy from previously exported entropy. See the ExportEntropy method for more information.
Returns 1 for success, 0 for failure.
RandomInt
Generates and returns a random integer between low and high (inclusive). For example, if low is 4 and high is 8, then random integers in the range 4, 5, 6, 7, 8 are returned.
RandomPassword
Generates and returns a random password of a specified length. If mustIncludeDigit is 1, the generated password will contain at least one digit (0-9). If upperAndLowercase is 1, then generated password will contain both lowercase and uppercase USASCII chars (a-z and A-Z). If mustHaveOneOf is a non-empty string, it contains the set of non-alphanumeric characters, one of which must be included in the password. For example, mustHaveOneOf might be the string "!@#$%". If excludeChars is a non-empty string, it contains chars that should be excluded from the password. A typical need would be to exclude chars that appear similar to others, such as i, l, 1, L, o, 0, O.
Returns Nothing on failure
RandomString
Generates and returns a random string that may contain digits (0-9), lowercase ASCII (a-z) , and uppercase ASCII (A-Z). To include numeric digits, set bDigits equal to 1. To include lowercase ASCII, set bLower equal to 1. To include uppercase ASCII, set bUpper equal to 1. The length of the string to be generated is specified by length.
Returns Nothing on failure