Secure Random Number Generator

Using the new flash.crypto.generateRandomBytes() method, ActionScript developers can generate a set of highly secure, random bytes for use in applications which require cryptographic keys for use in banking, finance, or even in the creation of general-use secure session ids applicable in just about any application which requires a heightened level of security. The actual functions which generate these cryptographically secure bytes actually are generated by the underlying operating system itself and not Flash Player.

In the example below, we will use this new method to generate a ByteArray object containing exactly 1024 randomly generated, cryptographically secure bytes.

package {
    import flash.crypto.generateRandomBytes; import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; import flash.utils.ByteArray; [SWF(width="600", height="500", backgroundColor="#CCCCCC")] public class RandomBytes extends Sprite { private var traceField:TextField; private var randBytes:ByteArray; public function RandomBytes() { generateDisplayObjects(); performOperations(); } protected function generateDisplayObjects():void { var defaultFormat:TextFormat = new TextFormat(); defaultFormat.font = "Arial"; defaultFormat.size = 22; defaultFormat.color = 0xFFFFFF; traceField = new TextField(); traceField.backgroundColor = 0x000000; traceField.alpha = 0.7; traceField.width = stage.stageWidth; traceField.height = stage.stageHeight; traceField.wordWrap ...

Get What's New in Flash Player 11 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.