Prng ActiveX Reference Documentation

Prng

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

(Visual Basic 6.0)
Dim obj As New ChilkatPrng

(ASP)
set obj = Server.CreateObject("Chilkat_9_5_0.Prng")

(VBScript)
set obj = CreateObject("Chilkat_9_5_0.Prng")

(Delphi)
obj := TChilkatPrng.Create(Self);

(FoxPro)
loObject = CreateObject('Chilkat_9_5_0.Prng')

(PowerBuilder)
lole_object = create oleobject
li_rc = lole_object.ConnectToNewObject("Chilkat_9_5_0.Prng")

(SQL Server)
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Prng', @obj OUT

(Javascript)
var obj = new ActiveXObject("Chilkat_9_5_0.Prng");

Properties

DebugLogFilePath As String

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

LastBinaryResult As Variant (read-only)

Introduced in version 9.5.0.52

The binary data returned by the last (binary data returning) method called. Only available if Chilkat.Global.KeepBinaryResult is set to 1. This provides a means for obtaining large varbinary results in the SQL Server environment (where limitations exist in getting large amounts of data returned by method calls, but where temp tables can be used for binary properties).

LastErrorHtml As String (read-only)

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

LastErrorText As String (read-only)

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

Concept of LastErrorText

LastErrorText Standard Information

LastErrorXml As String (read-only)

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

LastMethodSuccess As Long

Introduced in version 9.5.0.52

Indicate whether the last method call succeeded or failed. A value of 1 indicates success, a value of 0 indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = 1 and failure = 0.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to 1. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

LastStringResult As String (read-only)

Introduced in version 9.5.0.52

The string return value of the last (string returning) method called. Only available if Chilkat.Global.KeepStringResult is set to 1. This provides a means for obtaining large string results in the SQL Server environment (where limitations exist in getting long strings returned by method calls, but where temp tables can be used for string properties).

Long Strings Returned by ActiveX Methods in SQL Server

LastStringResultLen As Long (read-only)

Introduced in version 9.5.0.53

The length, in characters, of the string contained in the LastStringResult property.

PrngName As String

Introduced in version 9.5.0.52

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).

Fortuna PRNG Synopsis

Fortuna PRNG On Wikipedia

VerboseLogging As Long

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.

Version As String (read-only)

Version of the component/library, such as "9.5.0.63"

Methods

AddEntropy(entropy As String, encoding As String) As Long

Introduced in version 9.5.0.52

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.

Supported Binary Encodings

(Classic ASP) Fortuna PRNG Generate Random Encoded

(Visual FoxPro) Fortuna PRNG Generate Random Encoded

(PowerBuilder) Fortuna PRNG Generate Random Encoded

(SQL Server) Fortuna PRNG Generate Random Encoded

(Visual Basic 6.0) Fortuna PRNG Generate Random Encoded

(VBScript) Fortuna PRNG Generate Random Encoded

(Classic ASP) Adding Entropy to a PRNG

(Visual FoxPro) Adding Entropy to a PRNG

(PowerBuilder) Adding Entropy to a PRNG

(SQL Server) Adding Entropy to a PRNG

(Visual Basic 6.0) Adding Entropy to a PRNG

(VBScript) Adding Entropy to a PRNG

(Classic ASP) Generating Repeatable Random Data for Testing/Debugging

(Visual FoxPro) Generating Repeatable Random Data for Testing/Debugging

(PowerBuilder) Generating Repeatable Random Data for Testing/Debugging

(SQL Server) Generating Repeatable Random Data for Testing/Debugging

(Visual Basic 6.0) Generating Repeatable Random Data for Testing/Debugging

(VBScript) Generating Repeatable Random Data for Testing/Debugging

AddEntropyBytes(entropy As Variant) As Long

Introduced in version 9.5.0.52

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.

ExportEntropy() As String

Introduced in version 9.5.0.52

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

(Classic ASP) Exporting and Importing Accumulated Entropy

(Visual FoxPro) Exporting and Importing Accumulated Entropy

(PowerBuilder) Exporting and Importing Accumulated Entropy

(SQL Server) Exporting and Importing Accumulated Entropy

(Visual Basic 6.0) Exporting and Importing Accumulated Entropy

(VBScript) Exporting and Importing Accumulated Entropy

FirebasePushId() As String

Introduced in version 9.5.0.58

Generates a random Firebase Push ID. See Firebase Unique Identifiers.

Returns Nothing on failure

(Classic ASP) Generate a Random Firebase Push ID

(Visual FoxPro) Generate a Random Firebase Push ID

(PowerBuilder) Generate a Random Firebase Push ID

(SQL Server) Generate a Random Firebase Push ID

(Visual Basic 6.0) Generate a Random Firebase Push ID

(VBScript) Generate a Random Firebase Push ID

GenRandom(ByVal numBytes As Long, encoding As String) As String

Introduced in version 9.5.0.52

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

Supported Binary Encodings

(Classic ASP) Fortuna PRNG Generate Random Encoded

(Visual FoxPro) Fortuna PRNG Generate Random Encoded

(PowerBuilder) Fortuna PRNG Generate Random Encoded

(SQL Server) Fortuna PRNG Generate Random Encoded

(Visual Basic 6.0) Fortuna PRNG Generate Random Encoded

(VBScript) Fortuna PRNG Generate Random Encoded

GenRandomBd(ByVal numBytes As Long, bd As ChilkatBinData) As Long

Introduced in version 9.5.0.66

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.

(Classic ASP) SOAP WS-Security UsernameToken

(Visual FoxPro) SOAP WS-Security UsernameToken

(PowerBuilder) SOAP WS-Security UsernameToken

(SQL Server) SOAP WS-Security UsernameToken

(Visual Basic 6.0) SOAP WS-Security UsernameToken

(VBScript) SOAP WS-Security UsernameToken

GenRandomBytes(ByVal numBytes As Long) As Variant

Introduced in version 9.5.0.52

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(ByVal numBytes As Long, encoding As String) As String

Introduced in version 9.5.0.52

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

(Classic ASP) Fortuna PRNG Generate Random Encoded

(Visual FoxPro) Fortuna PRNG Generate Random Encoded

(PowerBuilder) Fortuna PRNG Generate Random Encoded

(SQL Server) Fortuna PRNG Generate Random Encoded

(Visual Basic 6.0) Fortuna PRNG Generate Random Encoded

(VBScript) Fortuna PRNG Generate Random Encoded

(Classic ASP) Adding Entropy to a PRNG

(Visual FoxPro) Adding Entropy to a PRNG

(PowerBuilder) Adding Entropy to a PRNG

(SQL Server) Adding Entropy to a PRNG

(Visual Basic 6.0) Adding Entropy to a PRNG

(VBScript) Adding Entropy to a PRNG

GetEntropyBytes(ByVal numBytes As Long) As Variant

Introduced in version 9.5.0.52

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(entropy As String) As Long

Introduced in version 9.5.0.52

Imports entropy from previously exported entropy. See the ExportEntropy method for more information.

Returns 1 for success, 0 for failure.

(Classic ASP) Exporting and Importing Accumulated Entropy

(Visual FoxPro) Exporting and Importing Accumulated Entropy

(PowerBuilder) Exporting and Importing Accumulated Entropy

(SQL Server) Exporting and Importing Accumulated Entropy

(Visual Basic 6.0) Exporting and Importing Accumulated Entropy

(VBScript) Exporting and Importing Accumulated Entropy

RandomInt(ByVal low As Long, ByVal high As Long) As Long

Introduced in version 9.5.0.52

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.

(Classic ASP) Generating Random Integer in Range

(Visual FoxPro) Generating Random Integer in Range

(PowerBuilder) Generating Random Integer in Range

(SQL Server) Generating Random Integer in Range

(Visual Basic 6.0) Generating Random Integer in Range

(VBScript) Generating Random Integer in Range

RandomPassword(ByVal length As Long, ByVal mustIncludeDigit As Long, ByVal upperAndLowercase As Long, mustHaveOneOf As String, excludeChars As String) As String

Introduced in version 9.5.0.52

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

(Classic ASP) Generating Random Password

(Visual FoxPro) Generating Random Password

(PowerBuilder) Generating Random Password

(SQL Server) Generating Random Password

(Visual Basic 6.0) Generating Random Password

(VBScript) Generating Random Password

RandomString(ByVal length As Long, ByVal bDigits As Long, ByVal bLower As Long, ByVal bUpper As Long) As String

Introduced in version 9.5.0.52

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

(Classic ASP) Generating Random ASCII Strings

(Visual FoxPro) Generating Random ASCII Strings

(PowerBuilder) Generating Random ASCII Strings

(SQL Server) Generating Random ASCII Strings

(Visual Basic 6.0) Generating Random ASCII Strings

(VBScript) Generating Random ASCII Strings