php - Key for HMAC Algorithm


Question: 

How to generate the secret key for the HMAC algorithm as I have to use it for data verification at the other clients end?

Thanks in advance.




1 Answer: 

The HMAC key must be pre-shared between the server and the client (both must known the key before you exchange messages).

You can generate the key in any way you want, for example by reading some bytes from /dev/random:

$fd = fopen('/dev/random', 'r');
$bytes = fread($fd, '64);

Then you can calculate the HMAC using hash_hmac:

$hash = hash_hmac('sha1', $data, $key);
 

More Articles


android - Mock location not working on Google map

I have used code from this. I have changed it a bit. Below is my code snippet. The problem is Google Map is not showing proper location which i have mocked.public class MockGpsProviderActivity extends Activity implements LocationListener {public static final String LOG_TAG = "MockGpsProviderActivity

git - How to use libgit2sharp with ssh-transport-protocol?

When I use libgit2sharp in project to clone repository with ssh-transport protocol, like git@github.com:libgit2/libgit2sharp.git It throw an exception, says "This transport isn't implemented. Sorry"How can I clone repository with ssh-transport-protocol by using libgit2sharp ?

C# HMAC SHA-256-128 Calculation result not as expected

I'm trying to create a signature to our bank from a specified key but my results is not the same as the info I got from the bank. Can anyone see what I am doing wrong?Link to bank for reference (text in Swedish)Example data are inside the citationmarks .. :)Filedata: "00000000"Key:


openssl - Send Push with .p8 and PHP

I need to send Push notifications through PHP script by using .p8 file and found following code in similar question asked here.<?php $keyfile = 'AuthKey_AABBCC1234.p8'; # <- Your AuthKey file $keyid = 'AABBCC1234'; # <- Your Key ID $teamid = 'AB12

java - log4j directs all log output to stdout even though it's not supposed to

In my log4j.properties I have:log4j.rootLogger=DEBUG,stdoutlog4j.logger.notRootLogger=DEBUG,somewhereelseThe appenders stdout and somewhereelse are both configured properly, stdout writes to the console and somewhereelse writes to a file.In my code in each class either I set either:static Logger log

android - Why getLastKnownLocation(provider) doesn't return null after clearTestProviderLocation(provider)

I was assuming that getLastKnownLocation does return null for a given provider after calling clearTestProviderLocation for same provider.Why ? because documentation says for clearTestProviderLocation; Removes any mock location associated with the given provider.public void test() throws SecurityExc


android - Mock Location permission issue on release app

I developed Fake GPS application and all my codes work nicely on debug mode.When i try "mock location" on **release version**, i got this error;java.lang.SecurityException: Requires `ACCESS_MOCK_LOCATION` permissionI already had ACCESS_MOCK_LOCATION in debug/AndroidManifest file.<uses-permission

regex - Regular expressions in R: pattern repetitions with {}

I am having trouble with a regular expression in R. The goal is to parse a Markdown/reST/knitr report text file in R to remove my own custom comments. These comments are put in the following form: Some sentence is about something <find a citation to this>.As Markdown uses <> for HTML tags,

cmake - How to build openCV 3.3.0 with GStreamer on Windows

Having Gstreamer 1.22 successfully installed I'm not able to configure the project to build OpenCV. CMake isn't able to find GStreamer on my machine. Any ideas how two address this issue?

sql server - How to add Text at the end of each line vb.net

I'm developing a program with VB.NET (2013), which works with a local database (sql server 2008 R2),The program is converting database tables into text files ,so how to add some text after the last field of each row at the end of each line in that text file,Thanks, And sorry for my englishIf mytable