Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        public void HashEncryptTest()
        {
            Console.WriteLine(DateTime.Now);
            int    i = 0;
            string x = SHAEncryptHelper.Hash256Encrypt("wKvbMYSvdnqXZAUq" + "QuMF3qJs4WrLJPB24bEzdLUlcxik6dDa");

            for (i = 0; i < 100000; i++)
            {
                x = SHAEncryptHelper.Hash256Encrypt(x);
            }
            Console.WriteLine("计算数量=" + i);
            Console.WriteLine(DateTime.Now);
            string c = SHAEncryptHelper.Hash256Encrypt("wKvbMYSvdnqXZAUq" + "QuMF3qJs4WrLJPB24bEzdLUlcxik6dDa");

            Console.WriteLine(c);
            c = SHAEncryptHelper.Hash1Encrypt("sssss");
            Console.WriteLine(c);
            c = SHAEncryptHelper.MD5Encrypt("sssss");
            Console.WriteLine(c);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        //下载全部的附件get all attachs by noteId
        public async Task <IActionResult> DownloadAll(string noteId)
        {
            var note = noteService.GetNoteById(noteId.ToLongByHex());

            if (note == null)
            {
                return(Content("No found note,Please check the  noteId"));
            }

            if (GetUserIdBySession() != note.UserId)
            {
                return(Content("No permission to access attachments"));
            }
            // 得到文件列表
            var attachs = await attachService.ListAttachsAsync(noteId.ToLongByHex(), GetUserIdBySession());

            if (attachs.IsNullOrNothing())
            {
                return(Content(""));
            }
            var sb        = new StringBuilder();
            var fileStore = FileStoreServiceFactory.Instance(config);

            //下载拼接
            foreach (var attach in attachs)
            {
                sb.Append(attach.AttachId);
            }
            //计算AttachId合并字符串的哈希
            string md5         = SHAEncryptHelper.MD5Encrypt(sb.ToString());
            var    dir         = config.FileStoreConfig.TempFolder + Path.DirectorySeparatorChar + note.NoteId.ToHex();
            var    zipFileName = config.FileStoreConfig.TempFolder + Path.DirectorySeparatorChar + md5 + ".zip";

            if (!System.IO.File.Exists(zipFileName))
            {
                //清理文件夹
                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }

                Directory.CreateDirectory(dir);

                //下载附件到本地
                foreach (var attach in attachs)
                {
                    string fileName = TextFilterUtil.DelUnSafeChar(attach.Title);
                    await fileStore.GetObjectAsync(config.MinIOConfig.NoteFileBucketName, attach.Path, dir + Path.DirectorySeparatorChar + fileName);
                }
                //执行压缩
                ZipHelper compressedFilesHelper = new ZipHelper();
                compressedFilesHelper.CreateZipFile(zipFileName, null, dir);
            }
            var memi = GetMemi(".zip");

            var stream = System.IO.File.Open(zipFileName, FileMode.Open, FileAccess.Read);

            {
                return(File(stream, memi, Path.GetFileName(zipFileName)));
            }
        }