$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;
$opts = [
'http' => [
'method' => "GET",
'header' => "publickey: " . $publicKey . "\r\n" .
"salt: " . $salt . "\r\n" .
"signature: " . $encodedSignature . "\r\n"
]
];
$result = file_get_contents('https://www.etermin.net/api/workingtimes?calendarid=1234', false, stream_context_create($opts));
var_dump($result);
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()
import random
import hmac
import base64
import hashlib
publicKey = "your-api-key"
privatekey = "your-secret-key-never-share-it"
# Generates a random string of ten digits
salt = str(random.getrandbits(32))
# Encode the privatekey and salt
privatekeyentcoded = privatekey.encode(encoding='utf-8', errors='strict')
saltentcoded = salt.encode(encoding='utf-8', errors='strict')
# Computes the signature by hashing the salt with the secret key as the key
signature = hmac.new(privatekeyentcoded, msg=saltentcoded, digestmod=hashlib.sha256).digest()
# Encode the signature
encodedSignature = base64.b64encode(signature)
encodedSignatureString = encodedSignature.decode(encoding='utf-8', errors='strict')
print("Your signature: "+encodedSignatureString)