Unity MD5 Encryption Process
Unity MD5 Password Generation
Hello everyone, in this article I will explain to you how you can encrypt a string with MD5 in Unity.
You can encrypt texts with MD5, you can encrypt your save files, and you can take a simple security measure for your game. (Of course, you can also use Unity outside its intended purpose to create a password or MD5 generator program.)
Our code and their explanations
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Our libraries
using System.Security.Cryptography;
using System.Text;
public class MD5Generator : MonoBehaviour
{
// Our code
public static string MD5Hash(string input)
{
StringBuilder hash = new StringBuilder(); // We create the string builder.
MD5CryptoServiceProvider md5provider = new MD5CryptoServiceProvider(); // We call our Cryptography function
byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(input)); // We set the encoding as bytes.
// We convert our code
for (int i = 0; i < bytes.Length; i++)
{
hash.Append(bytes[i].ToString("x2"));
}
return hash.ToString(); // We output the generated MD5 code.
}
}
MD5 can be stored as a StringBuilder and if you want to use it anywhere as Text/String, you need to call it with the ".ToString()" function. For extra security purposes, I recommend keeping and using it as a StringBuilder.
Yes friends, I have explained the code for generating MD5 as best as I can, if you have anything you are curious about, you can ask.

Yorum Gönder