简体   繁体   中英

What is the equivalent of .Net's GetHashCode() in PHP?

I am new to PHP scripting. I developed a VB.net application in which I am using GetHashCode() function for generating activation key. Now I want to generate activation key using PHP.

Can anyone help me to get the equivalent PHP function? Below I have written the example of VB.Net.

Dim MyString As String = "hello"
MsgBox(MyString.GetHashCode)

Output:

-695839

No, you can't do that with String.GetHashCode .

You can not persist result of String.GetHashCode as it may/will change between launches of the same program - so even if there is "equivalent" method in PHP you can't use really compare they results.

You need to use some custom code both sides agree on.

Ie use SHA256 to compute hash of the string - there are many samples how to compute hash in either language ie hmac_sha256 in php and c# differ covers both. If writing code yourself make sure to understand how to encode strings (ie UTF8) and result (ie Hex or Base64).

Yes, in .NET you can persist GetHashCode() results when using ValueTypes, the approach mentioned is only for Object (ReferenceTypes).

https://msdn.microsoft.com/pt-br/library/system.object.gethashcode(v=vs.110).aspx

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM