Example #1
0
        public void EncryptTest()
        {
            var str        = "oldli";
            var encryptStr = Md5Encrypt.Encrypt(str, true);

            Assert.Equal("5798a32794f531e50c12828665b715ad", encryptStr);
        }
Example #2
0
        /// <summary>
        /// 保存文件,返回文件的MD5值
        /// </summary>
        /// <param name="formFile">文件</param>
        /// <param name="savePath">保存路径</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns></returns>
        public async Task <string> SaveWithMd5(IFormFile formFile, string savePath, CancellationToken cancellationToken = default)
        {
            await using var stream = new FileStream(savePath, FileMode.Create);
            await formFile.CopyToAsync(stream, cancellationToken);

            stream.Seek(0, SeekOrigin.Begin);
            return(Md5Encrypt.Encrypt(stream));
        }
Example #3
0
        /// <summary>
        /// 保存文件,返回文件的MD5值
        /// </summary>
        /// <param name="formFile">文件</param>
        /// <param name="savePath">保存路径</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns></returns>
        public async Task <string> SaveWidthMd5(IFormFile formFile, string savePath, CancellationToken cancellationToken = default)
        {
            //写入
            await using var stream = new FileStream(savePath, FileMode.Create);
            var md5 = _md5Encrypt.Encrypt(stream);
            await formFile.CopyToAsync(stream, cancellationToken);

            return(md5);
        }
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="model"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <IResultModel <FileUploadResultModel> > Upload(FileUploadModel model, CancellationToken cancellationToken = default(CancellationToken))
        {
            var result = new ResultModel <FileUploadResultModel>();

            if (model.FormFile == null || model.FormFile.Length < 1)
            {
                if (model.Request.Form.Files != null && model.Request.Form.Files.Any())
                {
                    model.FormFile = model.Request.Form.Files[0];
                }
            }

            if (model.FormFile == null || model.FormFile.Length < 1)
            {
                return(result.Failed("请选择文件!"));
            }

            var resultModel = new FileUploadResultModel();
            var date        = DateTime.Now;

            resultModel.Name     = model.FormFile.FileName;
            resultModel.Ext      = Path.GetExtension(model.FormFile.FileName) ?? string.Empty;
            resultModel.Path     = Path.Combine(model.Group, date.ToString("yyyyMMdd"));
            resultModel.FileName = $"{date:yyyyMMddHHmmssfff}{resultModel.Ext}";
            resultModel.Size     = model.FormFile.Length;

            //删除后缀名的点
            if (resultModel.Ext.NotNull())
            {
                resultModel.Ext = resultModel.Ext.Replace(".", "");
            }

            var fullDir = Path.Combine(model.RootPath, resultModel.Path);

            if (!Directory.Exists(fullDir))
            {
                Directory.CreateDirectory(fullDir);
            }

            resultModel.Path = Path.Combine(resultModel.Path, resultModel.FileName);

            //写入
            var fullPath = Path.Combine(fullDir, resultModel.FileName);

            using (var stream = new FileStream(fullPath, FileMode.Create))
            {
                resultModel.Md5 = Md5Encrypt.Encrypt(stream);
                await model.FormFile.CopyToAsync(stream, cancellationToken);
            }

            return(result.Success(resultModel));
        }
Example #5
0
        /// <summary>
        /// 创建管理员账户
        /// </summary>
        private async Task AddAccount(Guid roleId)
        {
            var db      = DbContext.Set <AccountEntity>();
            var account = new AccountEntity
            {
                UserName     = "******",
                Password     = Md5Encrypt.Encrypt("admin_admin"),
                Name         = "管理员",
                CreatedTime  = DateTime.Now,
                CreatedBy    = Guid.Empty,
                ModifiedTime = DateTime.Now,
                ModifiedBy   = Guid.Empty,
                Deleted      = false,
                DeletedTime  = DateTime.Now,
                DeletedBy    = Guid.Empty
            };

            await db.InsertAsync(account);

            await AddAccountRole(account.Id, roleId);
        }
Example #6
0
 /// <summary>
 /// 密码加密
 /// </summary>
 /// <returns></returns>
 public string EncryptPassword(string userName, string password)
 {
     return(Md5Encrypt.Encrypt($"{userName}_{password}"));
 }
 /// <summary>
 /// 加密
 /// </summary>
 /// <param name="userName">用户名</param>
 /// <param name="password">密码</param>
 /// <returns></returns>
 public string Encrypt(string userName, string password)
 {
     return(Md5Encrypt.Encrypt($"{userName.ToLower()}_{password}"));
 }
Example #8
0
        public void EncryptTest()
        {
            var str = _encrypt.Encrypt("iamoldli");

            Assert.Equal("5108C4039CD470FD89B626E03EC0ABEE", str);
        }