Can't Encode MD5

Hello, I have a script that passes plain text to this script (code below) which sends the data to a php file which processes the plain text file and encrypts it with MD5. After encryption it is sent back to the file below, which is returned back to the original script. However, I’m getting a lot of errors. My errors are dealing with me being able to access the file from the code below. The file isn’t atttached to any object. But I can successfully utilize the main function Encrypt from the original script. The problem occurs when I get tot eh StartCoroutine, it says I can’t do the Coroutine because its non static. How do I fix this?

using UnityEngine;
using System.Collections;
using System.Security.Cryptography;

public class EncryptData : MonoBehaviour
{
	public float transparent;
	private string url;
	public WWW w;
	public WWWForm loginform = new WWWForm();
	public string formText;
	public string text;

	// Use this for initialization
	static void Start ()
	{
		
	}

	// Update is called once per frame
	void Update ()
	{
		
	}

	public static string Encrypt (string originaltext)
	{
		text = originaltext;
		StartCoroutine(EncryptText());
		print("string is " + formText);
		return(formText);
	}
	
	IEnumerator EncryptText()
	{
		url = "EncryptData.php?&text=" + WWW.EscapeURL (text);
		w = new WWW (url);
		yield return w;
		if (w.error != null) {
			print (w.error);
		}
		if (w.error == null) {
			formText = w.text;
			w.Dispose ();
			formText.Trim();
			StopAllCoroutines();
		}
	}
}

As we’ve established in the comments, the questioner was attempting to use www as a workaround to obtain a valid hash of a string. This is not necessary and the following sample code demonstrates how it might be done:

public static string ComputeHash(string s){
	// Form hash
	System.Security.Cryptography.MD5 h = System.Security.Cryptography.MD5.Create();
	byte[] data = h.ComputeHash(System.Text.Encoding.Default.GetBytes(s));
	// Create string representation
	System.Text.StringBuilder sb = new System.Text.StringBuilder();
	for (int i = 0; i < data.Length; ++i) {
		sb.Append(data*.ToString("x2"));*
  • }*
  • return sb.ToString();*
    }

You can’t create coroutines from static functions, because when you’re in the static function you don’t have a reference to an actual instance of the monobehaviour script. You have two ways to fix it:

-If your class is a singleton (you have a single instance if it in-scene), include an Instance variable that points to the instance in scene. You can set it from the Start() or Awake() functions, e.g.

public static EncryptData Instance;
void Start()
{
    Instance = this;
}

Or, you could use something like TaskManager, which gives you much more flexibility over using coroutines:

http://forum.unity3d.com/threads/94220-A-more-flexible-coroutine-interface