Turn a string into SHA512

Does anyone know how to do this in Unity? I’ve been trying for 12 hours…Thanks. I have this message and a “secret key” and I need it turned into SHA512

I really need working example code too

I’ve gathered that it might have something to do with System.Security.Cryptography’s SHA512Managed class, but I don’t understand how to use that class at all it makes no sense to me that is why I need a working example of it turning a string into SHA512

This hasn’t been tested in Unity, but it does work in a regular C# console application.

using System;
using System.Security.Cryptography;
using System.Text;

namespace ConsoleApplication1 {

    class Program {

        static void Main (string [] args) {

            Console.Write (GetSHA512 ("Hello World!"));
            Console.ReadLine ();
        }

        private static string GetSHA512 (string String) {

            UnicodeEncoding ue = new UnicodeEncoding ();
            byte [] hashValue;
            byte [] message = ue.GetBytes (String);

            SHA512Managed hashString = new SHA512Managed ();
            string hex = "";

            hashValue = hashString.ComputeHash (message);

            foreach (byte x in hashValue) {
                hex += String.Format ("{0:x2}", x);
            }

            return hex;
        }
    }
}

Above probably won’t work in Unity

string s = "Hello World";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes( s );
System.Security.Cryptography.SHA512 sha = System.Security.Cryptography.SHA512.Create();
byte[] hash = sha.ComputeHash( bytes );
string result = System.Text.Encoding.ASCII.GetString( hash );
Debug.Log( result );

This works

public static string GetSHA512(string text) {
        SHA512 sha = new SHA512Managed(); 

        //compute hash from the bytes of text 
        sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text)); 
   
        //get hash result after compute it 
        byte[] result = sha.Hash; 

        StringBuilder strBuilder = new StringBuilder(); 
        for (int i = 0; i < result.Length; i++) 
        { 
          //change it into 2 hexadecimal digits 
          //for each byte 
          strBuilder.Append(result[i].ToString("x2")); 
        } 
     
      return strBuilder.ToString();
}