A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: MD5 Hash Values

  1. #1
    Registered Deviant
    Join Date
    Sep 2004
    Location
    Cornelius, OR, USA
    Posts
    280

    MD5 Hash Values

    If anyone is interested in calculating MD5 hash values in their Flash files, I've thrown together some code in an ActionScript class for everyone to enjoy. Useful for calculating file checksums, password authentication and so forth.

    From the .AS file:
    Code:
    /* -----------------------------
    MD5Hash.as
    
    Creates a class called Hash.MD5Hash used to calculate the MD5 hash value of a given set of data.
    Place this file in a subdirectory named Hash in your classpath for ActionScript.
    
    Use 'import Hash.MD5Hash;' to include the .as file
    Use 'm = new MD5Hash("a");' to initialize a new instance
    
    Class exports the following functions
    // Constructor, takes one string
    	MD5Hash(s:String)
    
    // Getter/Setter functions
    	getText():String -- returns string passed to the constructor or setText() function
    	setText( s:String ):Void -- sets the internal data set to a new value and re-calculates the hash
    	getHash():String -- returns the last calculated hash value
    	toString():String -- synonym for getHash()
    	valueOf():String -- synonym for getHash()
    
    To re-use an existing Hash instance, simply call the setText() function with a new dataset, the hash
    value will be re-calculated instantly.
    
    Example:
    ////// BEGIN EXAMPLE //////
    import Hash.MD5Hash;
    
    m = new MD5Hash();
    trace( m.getText() + ": " + m.getHash() );
    // should return 'd41d8cd98f00b204e9800998ecf8427e'
    
    m.setText("");  // an undefined value is the same as an empty string, should get the same result
    trace( m.getText() + ": " + m.getHash() );
    // should also return 'd41d8cd98f00b204e9800998ecf8427e'
    
    m.setText("a");
    trace( m.getText() + ": " + m.getHash() );
    // should return '0cc175b9c0f1b6a831c399e269772661'
    
    m.setText( "The quick brown fox jumps over the lazy dog; what a boring and useless phrase" );
    trace( m.getText() + ": " + m.getHash() );
    // should return 'f35cbee66b5f212043f5d6a12472ed6c'
    //////  END EXAMPLE  //////
    
    Portions of this code were borrowed from http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html
    */
    Enjoy!
    Attached Files Attached Files

  2. #2
    Member
    Join Date
    Jan 2004
    Location
    Carlisle, UK
    Posts
    94

    Thumbs up

    I know this is an old thread, but thanks anyway!

    JT
    It is confirmed that I am quite sad. I told the wife I was 'loading' the pizza into the oven!

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    2
    Hey,
    Well, this is an old post, but some of you going thru this thread and looking for a tool to hash a string, try this online md5 converter
    David

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center