Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Dotnet c# language code missing in repository. Use attached code #2

Open
rajeshvaranasi66 opened this issue Dec 4, 2020 · 0 comments

Comments

@rajeshvaranasi66
Copy link

using Newtonsoft.Json;
using System;
using System.Security.Cryptography;
using System.Text;
namespace Helpers
{
public class sso
{
public Object GetUserSSOData()
{
Object user1 = null;
user1 = new
{
id = 66,
name = "Example user",
email = "[email protected]",
picture = "http://example.com/profile.png",
url = "https://example.com"
};
string json = JsonConvert.SerializeObject(user1);
var userData = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));
var hash = GetHashedMessage(userData);

        return new
        {
            Hash = hash,
            UserData = userData,
            LoginURL = "Your webiste login URL"
        };
    }

    private string GetHashedMessage(string _message)
    {
        string _secret = "You secret here";
        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
        byte[] keyByte = encoding.GetBytes(_secret);
        HMACSHA1 hmacsha1 = new HMACSHA1(keyByte);

        byte[] messageBytes = encoding.GetBytes(_message);
        byte[] hashmessage = hmacsha1.ComputeHash(messageBytes);
        return ByteToString(hashmessage).ToLower();
    }

    public string ByteToString(byte[] buff)
    {
        string sbinary = "";

        for (int i = 0; i < buff.Length; i++)
        {
            sbinary += buff[i].ToString("X2"); // hex format
        }
        return (sbinary);
    }
}

}

sso.zip

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant