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
otbuildotbuild 

Generate Authentication token

Hi,

 

We are using following C# code to generate authentication token. We with to migrate following code to Apex:

 

private static string GenerateAuthToken(string sInputName)
              {
                     try
                     {
                           // Concat SecretKey and AccountName which are the encryption parameters
                           string sEncryptionParameters = m_sSecretKey + sInputName;

                           // set the hashing key as the partner key
                           string sHashingKey = m_sPartnerKey;

                           // choose ASCII encoding
                           Encoding oCurrentEncoding = Encoding.ASCII;

                           // Use the hashing key to Encrypt the parameter list using HMAC-SHA1
                           HMACSHA1 oHMACSHA1 = new HMACSHA1(oCurrentEncoding.GetBytes(sHashingKey));

                           // Convert the EncryptionParameters into bytes
                           byte[] arrBytesEncryptionParameter = oCurrentEncoding.GetBytes(sEncryptionParameters);

                           // generate the auth token
                           string sAuthToken = BitConverter.ToString(oHMACSHA1.ComputeHash(arrBytesEncryptionParameter)).Replace("-", string.Empty).ToLower();

                           return sAuthToken;
                     }

 

 

The problem we are facing is we are not able to convert "String" to "Byte" and not finding "BitConverter" equivalent in Apex. Please suggest.

 

Thanks,

Prasad

otbuildotbuild

Hi,

 

I could migrate C# code to Apex code using methods of Blob and EncodingUtil classes.

 

Thanks,

Prasad