Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Charabis

Member Since 08 Apr 2006
Offline Last Active Apr 28 2013 04:31 PM

Topics I've Started

Javascript Equivalent of C# MD5

06 February 2012 - 01:36 PM

Actually, it's Javascript, but that's a different matter entirely. I have the following C# code that simply takes a string and encodes it:

public string CalculateMD5Unicode(string input)
{
	 // step 1, calculate MD5 hash from input
	 MD5 md5 = System.Security.Cryptography.MD5.Create();
	 byte[] inputBytes = System.Text.Encoding.Unicode.GetBytes(input);

	 byte[] hash = md5.ComputeHash(inputBytes);
	
	 return Convert.ToBase64String(hash);
}

Now I need to duplicate the output of this code in Javascript. So far, I've gotten it to where the same bytes are extracted:

function Process(str)
{

	var ch;
	var bytes = [];
	for(var i = 0; i < str.length; i++)
	{
		ch = str.charCodeAt(i);
		bytes.push(ch & 0xFF, ch>>>8);
	}
}

But I've hit a bit of a snag in trying to get the MD5 values to match. Specifically, this will be called from an HTML form to generate the same data currently being generated in the compiled C# program.

And yes, I know MD5 hashing is not terribly secure for doing passwords and what-not, but this is only going to be used until this gets closer to being released. Taking a lot of work to convince the guys in charge to buy an SSL certificate as they don't see it as being needed for testing. Isn't it fun to work for people who just don't know how to do...well anything Posted Image

Loading PNG In PHP And Returning It To C#

09 January 2012 - 04:43 PM

I'm working on a project that requires an array of textures. I'm looking to get the assets through PHP to avoid allowing direct access to them, but am having trouble getting them to return in a meaningful way. This is what I've built so far on the PHP side:

<?php
if(filter_has_var(INPUT_POST, "merchant") && filter_has_var(INPUT_POST, "test"))
{
$merchant = filter_input(INPUT_POST, "merchant", FILTER_SANITIZE_STRING);
$test = filter_input(INPUT_POST, "test", FILTER_SANITIZE_STRING);
}
else
{
die ("DataMissing");
}
$data_location = $_SERVER['DOCUMENT_ROOT'] . "/" . $merchant;
$arr = array();
if (is_dir($data_location))
{
    $dir = opendir($data_location) or die("Couldn't access directory!");
    while (($file = readdir($dir)) !== false)
    {
  $arr[] = file_get_contents($file);
    }
    echo $arr;
}
else
{
// Need to create it
mkdir($data_location, 0700) or die("Couldn't create " . $data_location);
echo "Empty";
}
?>

Creating the directory works fine, however I'm not seeming to get what I'd expect back to the C# program which calls it. In fact, with nothing in the folder, I seem to get back the string "Array". Needless to say, that's not what I expect or want!

PARTNERS