//////////////////////////////////////////////////////////////////////////////// // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// package UnitTest.Validation { import UnitTest.Validation.IntUtil; import flash.utils.ByteArray; /** * The MD5 Message-Digest Algorithm * * Implementation based on algorithm description at * http://www.faqs.org/rfcs/rfc1321.html */ public class MD5 { /** * Performs the MD5 hash algorithm on a string. * * @param s The string to hash * @return A string containing the hash value of s * @langversion ActionScript 3.0 * @playerversion Flash 8.5 * @tiptext */ public static function hash(s:String) :String{ //Convert to byteArray and send through hashBinary function // so as to only have complex code in one location var len:int = s.length; var ba:ByteArray = new ByteArray(); for(var i:int = 0; i 0xFF for( var i:int = 0; i < len; i += 8 ) { blocks[ i >> 5 ] |= ( s[ i / 8 ] & mask ) << ( i % 32 ); } // append padding and length blocks[ len >> 5 ] |= 0x80 << ( len % 32 ); blocks[ ( ( ( len + 64 ) >>> 9 ) << 4 ) + 14 ] = len; return blocks; } } }