Generating a SHA1 hash

Hi everyoe,

I'm trying to connect with a webService, and I must encode a part of the header with SHA1 encoding. I have an example in .NET, and I'm trying to convert it into C/AL, but I'm receiving an error from the webService. The code in .NET is this:

byte[] key = Encoding.UTF8.GetBytes(secret);
byte[] hmac_encode = Sha1Hash_Raw(concat, key);
string hmac_encode_base64 = System.Convert.ToBase64String(hmac_encode);

private static byte[] Sha1Hash_Raw(string input, byte[] key)
    HMACSHA1 sha1 = new HMACSHA1(key);
    byte[] byteArray = Encoding.UTF8.GetBytes(input);

    MemoryStream stream = new MemoryStream(byteArray);
    return sha1.ComputeHash(stream);

The value I must include into the header of the HTTP request is "hmac_encode_base64"

This is how I'm trying to generate the hash in NAV:

key := Encoding.UTF8.GetBytes(secret);
hmacSHA1 := hmacSHA1.Create;
hmacSHA1.Key  := key;
hmac_encode := hmacSHA1.ComputeHash(Encoding.UTF8.GetBytes(concat));
hmac_encode_base64 := Convert.ToBase64String(hmac_encode);

This are the variables:

secret    Text        
key    DotNet    System.Array.'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'    
hmac_encode_base64    Text        
hmacSHA1    DotNet    System.Security.Cryptography.HMACSHA1.'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'  
concat    Text        
hmac_encode    DotNet    System.Array.'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'   

Does anyone see any mistake or something I'm loosing?

Thnak you very much

Parents Reply Children
No Data