Packageair.security
Classpublic class Digest
InheritanceDigest Inheritance Object
ImplementsIDataOutput

Language version: ActionScript 3.0
Runtime version: AIR 50

The Digest class is used to generate a digest, or hash, of some data. It can be used to generate a fixed-length, one-way hash value based on arbitrary-sized data, to create a checksum and to attempt to quickly detect changes in data for validation purposes.

This class is similar to the Java java.security.MessageDigest implementation, and can be used in two ways:

  1. By creating an instance of the Digest class with a particular algorith, and then feeding data into the object using repeated calls to one of the IDataOutput methods, and finally then calling the digest method in order to calculate the hash value.
  2. By calling the static hash method with a ByteArray to perform the whole operation in a single call.

The supported algorithms are "SHA-1", "SHA-256", and "MD5".



Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  endian : String
The byte order for the data, either the BIG_ENDIAN or LITTLE_ENDIAN constant from the Endian class.
Digest
  objectEncoding : uint
Used to determine whether the AMF3 or AMF0 format is used when writing binary data using the writeObject() method.
Digest
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined by
  
Digest(algorithm:String)
Creates a Digest object using the requested algorithm
Digest
  
Generates the digest for data that has been passed into this object
Digest
  
hash(algorithm:String, data:ByteArray):ByteArray
[static] A utility function for creating the digest of some data in a single function call.
Digest
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
  
Resets the object for re-use by removing all earlier data
Digest
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
  
Writes a Boolean value.
Digest
  
writeByte(value:int):void
Writes a byte.
Digest
  
writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
Writes a sequence of bytes from the specified byte array, bytes, starting at the byte specified by offset (using a zero-based index) with a length specified by length, into the data to be used for the digest.
Digest
  
Writes an IEEE 754 double-precision (64-bit) floating point number.
Digest
  
Writes an IEEE 754 single-precision (32-bit) floating point number.
Digest
  
writeInt(value:int):void
Writes a 32-bit signed integer.
Digest
  
writeMultiByte(value:String, charSet:String):void
Writes a multibyte string to the file stream, byte stream, or byte array, using the specified character set.
Digest
  
writeObject(object:*):void
Writes an object to the file stream, byte stream, or byte array, in AMF serialized format.
Digest
  
Writes a 16-bit integer.
Digest
  
Writes a 32-bit unsigned integer.
Digest
  
Writes a UTF-8 string to the file stream, byte stream, or byte array.
Digest
  
Writes a UTF-8 string.
Digest
Public Constants
 ConstantDefined by
  MD5 : String = "MD5"
[static] Definition for the MD5 algorithm
Digest
  SHA1 : String = "SHA-1"
[static] Definition for the SHA-1 algorithm
Digest
  SHA256 : String = "SHA-256"
[static] Definition for the SHA-256 algorithm
Digest
  SHA512 : String = "SHA-512"
[static] Definition for the SHA-512 algorithm
Digest
Property detail
endianproperty
endian:String  [read-write]

Language version: ActionScript 3.0
Runtime version: AIR 50

The byte order for the data, either the BIG_ENDIAN or LITTLE_ENDIAN constant from the Endian class.

Implementation
    public function get endian():String
    public function set endian(value:String):void

See also

objectEncodingproperty 
objectEncoding:uint  [read-write]

Language version: ActionScript 3.0
Runtime version: AIR 50

Used to determine whether the AMF3 or AMF0 format is used when writing binary data using the writeObject() method. The value is a constant from the ObjectEncoding class.

Implementation
    public function get objectEncoding():uint
    public function set objectEncoding(value:uint):void

See also

IDataInput.readObject()
writeObject()
ObjectEncoding class
Constructor detail
Digest()constructor
public function Digest(algorithm:String)

Language version: ActionScript 3.0
Runtime version: AIR 50

Creates a Digest object using the requested algorithm

Parameters
algorithm:String — The message digest algorithm to use - SHA-1, SHA-256, SHA-512 or MD5
Method detail
digest()method
public function digest():ByteArray

Language version: ActionScript 3.0
Runtime version: AIR 50

Generates the digest for data that has been passed into this object

Returns
ByteArray — The digest value (as a ByteArray)
hash()method 
public static function hash(algorithm:String, data:ByteArray):ByteArray

Language version: ActionScript 3.0
Runtime version: AIR 50

A utility function for creating the digest of some data in a single function call.

Parameters
algorithm:String — The message digest algorithm to use - SHA-1, SHA-256, SHA-512 or MD5
 
data:ByteArray — A ByteArray object containing the data to perform the digest operation on.

Returns
ByteArray — The digest value (as a ByteArray)
reset()method 
public function reset():void

Language version: ActionScript 3.0
Runtime version: AIR 50

Resets the object for re-use by removing all earlier data

writeBoolean()method 
public function writeBoolean(value:Boolean):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes a Boolean value. A single byte is written according to the value parameter, either 1 if true or 0 if false.

Parameters
value:Boolean — A Boolean value determining which byte is written. If the parameter is true, 1 is written; if false, 0 is written.
writeByte()method 
public function writeByte(value:int):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes a byte. The low 8 bits of the parameter are used; the high 24 bits are ignored.

Parameters
value:int — A byte value as an integer.
writeBytes()method 
public function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes a sequence of bytes from the specified byte array, bytes, starting at the byte specified by offset (using a zero-based index) with a length specified by length, into the data to be used for the digest.

If the length parameter is omitted, the default length of 0 is used and the entire buffer starting at offset is written. If the offset parameter is also omitted, the entire buffer is written.

If the offset or length parameter is out of range, they are clamped to the beginning and end of the bytes array.

Parameters
bytes:ByteArray — The byte array to write.
 
offset:uint (default = 0) — A zero-based index specifying the position into the array to begin writing.
 
length:uint (default = 0) — An unsigned integer specifying how far into the buffer to write.
writeDouble()method 
public function writeDouble(value:Number):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes an IEEE 754 double-precision (64-bit) floating point number.

Parameters
value:Number — A double-precision (64-bit) floating point number.
writeFloat()method 
public function writeFloat(value:Number):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes an IEEE 754 single-precision (32-bit) floating point number.

Parameters
value:Number — A single-precision (32-bit) floating point number.
writeInt()method 
public function writeInt(value:int):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes a 32-bit signed integer.

Parameters
value:int — A byte value as a signed integer.
writeMultiByte()method 
public function writeMultiByte(value:String, charSet:String):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes a multibyte string to the file stream, byte stream, or byte array, using the specified character set.

Parameters
value:String — The string value to be written.
 
charSet:String — The string denoting the character set to use. Possible character set strings include "shift-jis", "cn-gb", "iso-8859-1", and others. For a complete list, see Supported Character Sets.
writeObject()method 
public function writeObject(object:*):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes an object to the file stream, byte stream, or byte array, in AMF serialized format.

Parameters
object:* — The object to be serialized.

See also

writeShort()method 
public function writeShort(value:int):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes a 16-bit integer. The low 16 bits of the parameter are used; the high 16 bits are ignored.

Parameters
value:int — A byte value as an integer.
writeUnsignedInt()method 
public function writeUnsignedInt(value:uint):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes a 32-bit unsigned integer.

Parameters
value:uint — A byte value as an unsigned integer.
writeUTF()method 
public function writeUTF(value:String):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes a UTF-8 string to the file stream, byte stream, or byte array. The length of the UTF-8 string in bytes is written first, as a 16-bit integer, followed by the bytes representing the characters of the string.

Parameters
value:String — The string value to be written.

Throws
RangeError — If the length is larger than 65535.
writeUTFBytes()method 
public function writeUTFBytes(value:String):void

Language version: ActionScript 3.0
Runtime version: AIR 50

Writes a UTF-8 string. Similar to writeUTF(), but does not prefix the string with a 16-bit length word.

Parameters
value:String — The string value to be written.
Constant detail
MD5constant
public static const MD5:String = "MD5"

Definition for the MD5 algorithm

SHA1constant 
public static const SHA1:String = "SHA-1"

Definition for the SHA-1 algorithm

SHA256constant 
public static const SHA256:String = "SHA-256"

Definition for the SHA-256 algorithm

SHA512constant 
public static const SHA512:String = "SHA-512"

Definition for the SHA-512 algorithm