$publicKey = "your-api-key";
$privateKey = "your-secret-key-never-share-it";
// Generates a random string of ten digits
$salt = mt_rand();
// Computes the signature by hashing the salt with the secret key as the key
$signature = hash_hmac('sha256', $salt, $privateKey, true);
// base64 encode
$encodedSignature = base64_encode($signature);
echo "Your signature: " . $encodedSignature;
var publicKey = "your-api-key";
var privateKey = "your-secret-key-never-share-it";
// Generate a new globally unique identifier for the salt
var salt = System.Guid.NewGuid().ToString();
// Initialize the keyed hash object using the secret key as the key
HMACSHA256 hashObject = new HMACSHA256(Encoding.UTF8.GetBytes(privateKey));
// Computes the signature by hashing the salt with the secret key as the key
var signature = hashObject.ComputeHash(Encoding.UTF8.GetBytes(salt));
// Base 64 Encode
string encodedSignature = Convert.ToBase64String(signature);
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
using (WebClient client = new WebClient())
{
client.Headers.Add("publickey", publicKey);
client.Headers.Add("salt", salt);
client.Headers.Add("signature", encodedSignature);
byte[] response = client.UploadValues("https://www.etermin.net/api/contact", "POST", new NameValueCollection()
{
{ "email", "email@example.com" },
{ "firstname", "Thomas" },
{ "lastname", "Mueller" }
});
string result = System.Text.Encoding.UTF8.GetString(response);
}
Dim publicKey = "your-api-key"
Dim privateKey = "your-secret-key-never-share-it"
' Generate a new globally unique identifier for the salt
Dim salt = System.Guid.NewGuid().ToString()
' Initialize the keyed hash object using the secret key as the key
Dim hashObject As New HMACSHA256(Encoding.UTF8.GetBytes(privateKey))
' Computes the signature by hashing the salt with the secret key as the key
Dim signature = hashObject.ComputeHash(Encoding.UTF8.GetBytes(salt))
' Base 64 Encode
Dim encodedSignature = Convert.ToBase64String(signature)
Console.WriteLine("Your signature: " & encodedSignature)
Console.ReadKey()
publicKey = "your-api-key"
privatekey = "your-secret-key-never-share-it"
# Generates a random string of ten digits
salt = str(random.getrandbits(32))
# Computes the signature by hashing the salt with the secret key as the key
signature = hmac.new(privatekey, msg=salt, digestmod=hashlib.sha256).digest()
# base64 encode...
encodedSignature = base64.encodestring(signature).replace('\n', '')
print "Your signature: " + encodedSignature