- Code: Select all
Imports System
Imports System.Text
Imports System.Security.Cryptography
Namespace PlayerIOConnect
Public Class PlayerIOAuth
Public Shared Function Create(ByVal userId As String, ByVal sharedSecret As String) As String
Dim unixTime As Integer = CInt((DateTime.UtcNow - New DateTime(1970, 1, 1)).TotalSeconds)
Dim hmac = New HMACSHA1(Encoding.UTF8.GetBytes(sharedSecret)).ComputeHash(Encoding.UTF8.GetBytes((unixTime & ":") + userId))
Return (unixTime & ":") + toHexString(hmac)
End Function
Private Shared Function toHexString(ByVal bytes As Byte()) As String
Dim hex As New StringBuilder(bytes.Length * 2)
For Each b As Byte In bytes
hex.AppendFormat("{0:x2}", b)
Next
Return hex.ToString()
End Function
Private Shared Sub Main(ByVal args As String())
Console.WriteLine("bob: " & Create("bob", "nobody can know this string"))
Console.WriteLine("Joan1234: " & Create("Joan1234", "1234$@_abc"))
Console.ReadLine()
End Sub
End Class
End Namespace
There you go