Browse Source

Use StringTools.hex for Sha1 and Sha256 (Md5's hex representation
is little-endian, so cannot use the big-endian StringTools.hex)

Joey Smith 10 years ago
parent
commit
6b1c2bc661
2 changed files with 4 additions and 14 deletions
  1. 2 7
      std/haxe/crypto/Sha1.hx
  2. 2 7
      std/haxe/crypto/Sha256.hx

+ 2 - 7
std/haxe/crypto/Sha1.hx

@@ -167,15 +167,10 @@ class Sha1 {
 
 	function hex( a : Array<Int> ){
 		var str = "";
-		var hex_chr = "0123456789abcdef";
 		for( num in a ) {
-			var j = 7;
-			while( j >= 0 ) {
-				str += hex_chr.charAt( (num >>> (j<<2)) & 0xF );
-				j--;
-			}
+			str += StringTools.hex(num, 8);
 		}
-		return str;
+		return str.toLowerCase();
 	}
 
 	#end

+ 2 - 7
std/haxe/crypto/Sha256.hx

@@ -183,15 +183,10 @@ class Sha256 {
 	
 	function hex( a : Array<Int> ){
 		var str = "";
-		var hex_chr = "0123456789abcdef";
 		for( num in a ) {
-			var j = 7;
-			while( j >= 0 ) {
-				str += hex_chr.charAt( (num >>> (j<<2)) & 0xF );
-				j--;
-			}
+			str += StringTools.hex(num, 8);
 		}
-		return str;
+		return str.toLowerCase();
 	}
 
 }