Updated C# Example on how to calculate the Signature
ZixtysAdmin
Thu, 30 Jan 2020 18:22:03 GMT
Hello Everyone,
The C# example in the Muut document for calculating the signature doesn't work and has some syntax errors. It also doesn't use Newtonsoft for Serialization. There was a post a few years back with a solution and I just took it and updated it.
using System;
using System.Security.Cryptography;
using System.Text;
var user = new
{
user = new
{
id = "1",
email = "[email protected]",
displayname = "John Doe",
avatar = "url",
is_admin = false
}
};
//Add your Muut Secret Key
string secretkey = "PutYourSecretKeyHere!"
long timestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
try
{
//Message
//use Newtonsoft Serializer
string messageJSON = Newtonsoft.Json.JsonConvert.SerializeObject(user);
var messageBytes = Encoding.ASCII.GetBytes(messageJSON);
var message64 = Convert.ToBase64String(messageBytes);
var sgn = secretkey + " " + message64 + " " + timestamp.ToString();
var signatureBytes = Encoding.ASCII.GetBytes(sgn);
var hashedSignature = new SHA1CryptoServiceProvider().ComputeHash(signatureBytes);
var signature = BitConverter.ToString(hashedSignature).Replace("-", string.Empty).ToLower();
Console.WriteLine("Time Stamp= " + timestamp);
Console.WriteLine("Signature = " + signature);
}
catch (Exception e)
{
string excp = e.Message;
}
simplyadmin
Fri, 31 Jan 2020 12:09:58 GMT
Hmm, I think 'signature' is being used two ways here. I mean a bit of text that the user can set up that automatically appears on the bottom of all their posts.