Public Methods
| Function | Defined By | ||
|---|---|---|---|
generateRandomBytes(numberRandomBytes:uint):ByteArray
Provides a mechanism to generate a cryptographically secure random byte sequence. | flash.crypto | ||
Function detail
generateRandomBytes | () | function |
public function generateRandomBytes(numberRandomBytes:uint):ByteArray| Runtime Versions: | 3 |
Provides a mechanism to generate a cryptographically secure random byte sequence.
Use generateRandomBytes() to generate:
- Cryptographic keys
- Session keys for encrypting data
- Strong identifiers, such as GUIDs
- Message IDs
- Seed data for pseudorandom number generators
The generateRandomBytes() function generates a random sequence of bytes by utilizing cryptographically strong functions in
the underlying operating system:
-
Windows:
CryptGenRandom() -
Mac OS:
/dev/random -
Linux:
/dev/random -
Android:
/dev/urandom -
iOS:
SecRandomCopyBytes()
If this function is not able to return a sequence of random bytes, then Error Code 3403 is thrown. The accompanying message is "Random Number Generation failed". The following scenarios cause the error to be thrown:
-
On Windows: When
CryptGenRandom()or any associated APIs return any error -
On Mac OS and Linux: When
/dev/randomis not mounted -
On Android: When
/dev/urandomis not mounted -
On iOS: When
SecRandomCopyBytes()returns-1
Parameters
numberRandomBytes:uint — The number of random bytes to generate, between 1 and 1024.
|
ByteArray — A ByteArray containing the generated random bytes.
|
Throws
Error — When random bytes were not generated.
|
Thu Sep 29 2011, 02:35 AM -07:00
