Exemplo n.º 1
0
        public static JWT GetJWT(long tokenId, string userNmae, long userId, string group, long exp = 31536000)
        {
            JWT_Header header = new JWT_Header()
            {
                alg = "sha1"
            };
            JWT_Payload payload = new JWT_Payload
            {
                tokenId   = tokenId,
                iss       = "localhost",
                username  = userNmae,
                userId    = userId,
                group     = group,
                startTime = UnixTimeHelper.GetTimeStampInLong(),
                exp       = exp,
                random    = RandomTool.CreatSafeNum(8)
            };
            StringBuilder message = new StringBuilder();

            message.Append(header.alg);
            message.Append(payload.tokenId);
            message.Append(payload.iss);
            message.Append(payload.username);
            message.Append(payload.userId);
            message.Append(payload.group);
            message.Append(payload.startTime);
            message.Append(payload.exp);
            message.Append(payload.random);
            string password  = "";
            string signature = SHAEncrypt_Helper.Hash1Encrypt(message + password);
            JWT    jWT       = new JWT()
            {
                Header    = header,
                Payload   = payload,
                Signature = signature
            };

            return(jWT);
        }
Exemplo n.º 2
0
        public void CreatSafeNumTest()
        {
            string safe = RandomTool.CreatSafeNum();

            Console.WriteLine(safe);
        }