Package functions description.
Public Methods
Function | Defined By | ||
---|---|---|---|
Provides a mechanism to generate a cryptographically secure random byte sequence. | flash.crypto |
Function detail
generateRandomBytes | () | function |
public function generateRandomBytes(numberRandomBytes:uint):ByteArray
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 11, AIR 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/random
is not mounted -
On Android: When
/dev/urandom
is 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.
|
Related API Elements
Mon Nov 28 2011, 07:46 AM -08:00