function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Antoine LELEU 10Antoine LELEU 10 

Java Hash Function to Apex

Hello,

I would like to use this hash function in Apex. Is it possible to Mapp this java function in apex function ?

public string Hash(string ToHash)
        {
            ToHash = ToHash.ToLower();
            Encoder enc = System.Text.Encoding.ASCII.GetEncoder();
            byte[] data = new byte[ToHash.Length];
            enc.GetBytes(ToHash.ToCharArray(), 0, ToHash.Length, data, 0, true);
            SHA1 sha1 = new SHA1CryptoServiceProvider();
            byte[] result = sha1.ComputeHash(data);
            return BitConverter.ToString(result).Replace("-", "").ToLower();
        }

Thanks for your help !
Antoine
AshlekhAshlekh
Hi,

You can use Crypto class and their function.

https://developer.salesforce.com/page/Apex_Crypto_Class

-Thanks
Ashlekh Gera
Antoine LELEU 10Antoine LELEU 10
Hi AKG,

Thanks for your answer.
I already knew this Apex_Crypto_Class but i'm not able to transcode the function from C# to Apex.

Can you help me ?

Thanks,
Antoine