{"id":5129,"date":"2021-10-13T04:26:35","date_gmt":"2021-10-13T04:26:35","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=5129"},"modified":"2021-10-13T05:42:37","modified_gmt":"2021-10-13T05:42:37","slug":"php-hash_hmac-function","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/","title":{"rendered":"PHP &#8211; hash_hmac() Function"},"content":{"rendered":"<h2>Definition and Usage<\/h2>\n<p>The hash_hmac() function generates keyed hash values using the HMAC algorithm.<br \/>\nHMAC is an abbreviation for keyed-hash message authentication code or hash-based message <a href=\"https:\/\/studysection.com\/blog\/firebase-authentication-using-angular\/\">authentication<\/a> code. It makes use of cryptographic hash functions like md5, sha-256, and a secret key to return the message digest hash of the given data.<\/p>\n<h3>Syntax<\/h3>\n<p><code>hash_hmac ( string $algo , string $data , string $key [, bool $raw_output = FALSE ] ) : string<\/code><\/p>\n<h3>Parameters<\/h3>\n<table class=\"table table-striped\" style=\"max-width:600px;\">\n<thead>\n<tr>\n<th>Parameter<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>algo<\/td>\n<td>Name of the hashing algorithm. Hash supports a wide range of algorithms, including md5, sha256, and others.<br \/>\nTo see the complete list of available algorithms, look for hash_hmac_algos()\n<\/td>\n<\/tr>\n<tr>\n<td>data<\/td>\n<td>The data you want to hash.<\/td>\n<\/tr>\n<tr>\n<td>key<\/td>\n<td>The secret key to generate HMAC variant of the message digest.<\/td>\n<\/tr>\n<tr>\n<td>raw_output<\/td>\n<td>The value is false by default, thus it returns lowercase hexits. It will return raw binary data if the value is true.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Return Values<\/strong><br \/>\nThe hash_hmac() method returns a string with a computed message digest in lowercase hexits. If raw_output is set to false, raw binary data will be returned.<br \/>\n<strong>PHP Version<\/strong><br \/>\nThis function will work with PHP versions greater than 5.1.2.<br \/>\n<strong>Example 1<\/strong><br \/>\nUsing hash_hmac() \u2212<br \/>\n<code>&lt;?php<br \/>\n     echo hash_hmac('md5', 'PHP - Hash hmac() Function', 'any_secretkey');<br \/>\n?><\/code><\/p>\n<h3>Output<\/h3>\n<p>This will produce the following result \u2212<br \/>\n<code><em>65f76c2b226b566b03a467bbcfba6a58<\/em><\/code><\/p>\n<p><strong>Example 2<\/strong><br \/>\nUsing hash_hmac() with ripemd128 algorithm \u2212<br \/>\n<code>&lt;?php<br \/>\n   echo hash_hmac('ripemd128', 'PHP - Hash hmac() Function', 'any_secretkey');<br \/>\n?><\/code><\/p>\n<h3>Output<\/h3>\n<p>This will produce the following result \u2212<br \/>\n<code><em>3955f952d6326196099da6f70bda9e2d<\/em><\/code><\/p>\n<p><strong>Example 3<\/strong><br \/>\nTo create hash_hmac with raw output set to true \u2212<br \/>\n<code>&lt;?php<br \/>\n   echo hash_hmac('ripemd128', 'PHP - Hash hmac() Function', 'any_secretkey', true);<br \/>\n?><\/code><\/p>\n<h3>Output<\/h3>\n<p>This will produce the following result \u2212<br \/>\n<code>9U'R'2a' '''<br \/>\n\u069e-<\/code><\/p>\n<p><small><em>People having good command over the French language can get a French certification from StudySection. StudySection offers both beginner level and expert level <a href=\"https:\/\/www.studysection.com\/french-language-and-concepts-advanced\">French Certification Exams<\/a> to test the ability to communicate in the French language.<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Definition and Usage The hash_hmac() function generates keyed hash values using the HMAC algorithm. HMAC is an abbreviation for keyed-hash<\/p>\n","protected":false},"author":1,"featured_media":5130,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[200],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP - hash_hmac() Function - StudySection Blog<\/title>\n<meta name=\"description\" content=\"The hash_hmac() function generates keyed hash values using the HMAC algorithm.HMAC is an abbreviation for keyed-hash message authentication code\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP - hash_hmac() Function - StudySection Blog\" \/>\n<meta property=\"og:description\" content=\"The hash_hmac() function generates keyed hash values using the HMAC algorithm.HMAC is an abbreviation for keyed-hash message authentication code\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-13T04:26:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-13T05:42:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/Function.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"PHP &#8211; hash_hmac() Function\",\"datePublished\":\"2021-10-13T04:26:35+00:00\",\"dateModified\":\"2021-10-13T05:42:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/\"},\"wordCount\":256,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"php\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/\",\"url\":\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/\",\"name\":\"PHP - hash_hmac() Function - StudySection Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2021-10-13T04:26:35+00:00\",\"dateModified\":\"2021-10-13T05:42:37+00:00\",\"description\":\"The hash_hmac() function generates keyed hash values using the HMAC algorithm.HMAC is an abbreviation for keyed-hash message authentication code\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP &#8211; hash_hmac() Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP - hash_hmac() Function - StudySection Blog","description":"The hash_hmac() function generates keyed hash values using the HMAC algorithm.HMAC is an abbreviation for keyed-hash message authentication code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/","og_locale":"en_US","og_type":"article","og_title":"PHP - hash_hmac() Function - StudySection Blog","og_description":"The hash_hmac() function generates keyed hash values using the HMAC algorithm.HMAC is an abbreviation for keyed-hash message authentication code","og_url":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2021-10-13T04:26:35+00:00","article_modified_time":"2021-10-13T05:42:37+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/Function.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"PHP &#8211; hash_hmac() Function","datePublished":"2021-10-13T04:26:35+00:00","dateModified":"2021-10-13T05:42:37+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/"},"wordCount":256,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["php"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/php-hash_hmac-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/","url":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/","name":"PHP - hash_hmac() Function - StudySection Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2021-10-13T04:26:35+00:00","dateModified":"2021-10-13T05:42:37+00:00","description":"The hash_hmac() function generates keyed hash values using the HMAC algorithm.HMAC is an abbreviation for keyed-hash message authentication code","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/php-hash_hmac-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/php-hash_hmac-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP &#8211; hash_hmac() Function"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":977,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5129"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=5129"}],"version-history":[{"count":7,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5129\/revisions"}],"predecessor-version":[{"id":5137,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5129\/revisions\/5137"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/5130"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=5129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=5129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=5129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}