Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 244181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:59:00+00:00 2026-05-11T20:59:00+00:00

we previously use a C#.net 2.0 to create a web app. Users password were

  • 0

we previously use a C#.net 2.0 to create a web app.

Users password were hashed and stored in database using the following code.

private const string encryptionKey = "AE09F72B007CAAB5";

HMACSHA1 hash = new HMACSHA1();
hash.Key = HexToByte(encryptionKey);
encodedPassword = Convert.ToBase64String(
    hash.ComputeHash(Encoding.Unicode.GetBytes(password)));

now we intend to migrate to php.

so we face a problem for users when they want to back in.

what php equivalent of the method should be used so that the hash values in the database would work?

eg password to encode is pa55w0rd
the hash value gotten is oK9NOVhpTkxLoLfvh1430SFb5gw=

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:59:00+00:00Added an answer on May 11, 2026 at 8:59 pm

    In your C# app you generate the byte[] arrays in two different ways with a little bit different results. Your PHP script needs to emulate them exactly.

    hash.Key = HexToByte(encryptionKey)

    You pass in a 16 characters long string and get an array of 8 bytes, just like hash.Key = new byte[]{0xAE, 0x09, 0xF7, 0x2B, 0x00, 0x7C, 0xAA, 0xB5 }; but

    string password = "pa55w0rd";
    byte[] b = Encoding.Unicode.GetBytes(password)

    returns an array with 16 elements because of the Encoding.Unicode, like byte[] b = { 0x112, 0x0, 0x97, 0x0, 0x53, 0x0, 0x53, 0x0, 0x119, 0x0, 0x48, 0x0, 0x114, 0x0,0x100, 0x0 }
    In your php script you can change the encoding of $password to utf-16le with $data = mb_convert_encoding($password, 'UTF16-LE') to achieve a similar result. hash_hmac() being unaware of any encoding will treat the string a 16 byte single-byte encoded string, just like hash.ComputeHash(byte[]) in .net does.

    <?php
    $password = "pa55w0rd";
    $key = HexToBytes("AE09F72B007CAAB5"); // 8 bytes, hex

    // $to must be 'UTF-16LE'
    // $from depends on the "source" of $password
    $data = mb_convert_encoding($password, 'UTF-16LE', 'ASCII');

    // I've saved this script as an ascii file -> the string literal is ASCII encoded
    // therefore php's strlen() returns 8 for $password and 16 for $data
    // this may differ in your case, e.g. if the contents of $password comes from a
    // http-request where the data is utf-8 encoded. Adjust the $from parameter for
    // mb_convert_encoding() accordingly
    echo 'Debug: |data|=', strlen($data), ' |password|=', strlen($password), "\n";

    $h = HexToBytes(hash_hmac('sha1', $data, $key));
    echo 'hmac-sha1: ', base64_encode($h);

    function HexToBytes($s) {
    // there has to be a more elegant way...
    return join('', array_map('chr', array_map('hexdec', str_split($s, 2))));
    }prints

    Debug: |data|=16 |password|=8
    hmac-sha1: oK9NOVhpTkxLoLfvh1430SFb5gw=

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 162k
  • Answers 162k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try running a profiler on it. May 12, 2026 at 11:56 am
  • Editorial Team
    Editorial Team added an answer The only true "commercial-grade" split button that I know of… May 12, 2026 at 11:56 am
  • Editorial Team
    Editorial Team added an answer "Static" and "dynamic" aren't the right descriptions for that. ->… May 12, 2026 at 11:56 am

Related Questions

We have a web service that we will be hosting on a public web
Where I work we're still on .Net 2.0, but I'm somewhat familiar with the
Two questions: Can someone point me to unbiased data that compares .NET performance to
What is the best continuous integration setup for a Devleopment department that codes in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.