Adobe® AIR® API Reference for HTML Developers
Home  |  Hide Classes List |  Index  |  Appendixes

Language Reference only       
Package flash.crypto 

Public Methods
 FunctionDefined 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/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.

Returns
ByteArray — A ByteArray containing the generated random bytes.

Throws
Error — When random bytes were not generated.