게임엔진관련/유니티 엔진

[Unity] 유니티 MD5 관련

AlrepondTech 2021. 2. 4. 10:44
반응형

 

 

 

 

 

 

 

=======================

=======================

=======================

 

 

 

 

 

 

 

 

 

 

 

출처 : http://wiki.unity3d.com/index.php?title=MD5

 

C#용

public  string Md5Sum(string strToEncrypt)
{
	System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
	byte[] bytes = ue.GetBytes(strToEncrypt);
 
	// encrypt bytes
	System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
	byte[] hashBytes = md5.ComputeHash(bytes);
 
	// Convert the encrypted bytes back to a string (base 16)
	string hashString = "";
 
	for (int i = 0; i < hashBytes.Length; i++)
	{
		hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
	}
 
	return hashString.PadLeft(32, '0');
}

 

 

 

 

반응형

 

728x90





JavaScript용

#pragma strict
 
static function Md5Sum(strToEncrypt: String)
{
	var encoding = System.Text.UTF8Encoding();
	var bytes = encoding.GetBytes(strToEncrypt);
 
	// encrypt bytes
	var md5 = System.Security.Cryptography.MD5CryptoServiceProvider();
	var hashBytes:byte[] = md5.ComputeHash(bytes);
 
	// Convert the encrypted bytes back to a string (base 16)
	var hashString = "";
 
	for (var i = 0; i < hashBytes.Length; i++)
	{
		hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, "0"[0]);
	}
 
	return hashString.PadLeft(32, "0"[0]);
}

 

 

 

=======================

=======================

=======================

 

 

 

 

 

반응형