public void InitSecret() { Console.WriteLine(" ==================== Initializing Secret Start==================== "); ConfigFileService configFileService = new ConfigFileService(); configFileService.WebConfig.SecurityConfig.Secret = RandomTool.CreatSafeRandomBase64(32); configFileService.Save(); Console.WriteLine(" ==================== Initialized Secret Successfully ==================== "); }
public IActionResult TakeNumber() { var re = new ApiRe(); //产生一个序号 var id = idGenerator.NextId();//序号 var random = RandomTool.CreatSafeRandomBase64(16); var data = SHAEncryptHelper.Hash256Encrypt(id + random); distributedCache.SetBool("TakeNumber", true); re.Data = data; re.Ok = true; return(LeanoteJson(re)); }
public ServerChallenge GenServerChallenge(string tag, string requestNumber, long?userId) { //随机数 var random = RandomTool.CreatSafeRandomBase64(32); var challenge = new ServerChallenge() { Id = this.idGenerator.NextId(), UserId = userId, Tag = tag, RequestNumber = requestNumber, Random = random, UinxTime = UnixTimeUtil.GetTimeStampInInt32() }; SaveServerChallenge(challenge); return(challenge); }
public 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 = UnixTimeUtil.GetTimeStampInLong(), exp = exp, random = RandomTool.CreatSafeRandomBase64(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 = SHAEncryptHelper.Hash1Encrypt(message + password); JWT jWT = new JWT() { Header = header, Payload = payload, Signature = signature }; return(jWT); }
public void CreatSafeNumTest() { string safe = RandomTool.CreatSafeRandomBase64(); Console.WriteLine(safe); }