Ejemplo n.º 1
0
        public string Encrypt([FromBody] EncryptDataDto requestDto)
        {
            string data = requestDto.ObjectData.ToString(Newtonsoft.Json.Formatting.None);
            var    key  = requestDto.Key ?? MixService.GetAppSetting <string>(MixAppSettingKeywords.ApiEncryptKey);

            return(AesEncryptionHelper.EncryptString(data, key));
        }
Ejemplo n.º 2
0
        public RepositoryResponse <string> Encrypt([FromBody] JObject model)
        {
            string data      = model.GetValue("data").Value <string>();
            var    encrypted = new JObject(new JProperty("encrypted", data));
            var    key       = System.Text.Encoding.UTF8.GetBytes("sw-cms-secret-key");

            return(new RepositoryResponse <string>()
            {
                Data = AesEncryptionHelper.EncryptString(data, Convert.ToBase64String(key))
            });
        }
Ejemplo n.º 3
0
        public RepositoryResponse <string> Encrypt([FromBody] JObject model)
        {
            string data      = model.GetValue("data").Value <string>();
            var    encrypted = new JObject(new JProperty("encrypted", data));
            var    key       = MixService.GetConfig <string>(MixAppSettingKeywords.ApiEncryptKey);

            return(new RepositoryResponse <string>()
            {
                Data = AesEncryptionHelper.EncryptString(data, key)
            });
        }
Ejemplo n.º 4
0
        public override MixPostAttributeValue ParseModel(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            if (string.IsNullOrEmpty(Id))
            {
                Id = Guid.NewGuid().ToString();
                CreatedDateTime = DateTime.UtcNow;
            }

            if (Field.IsEncrypt && !string.IsNullOrEmpty(StringValue))
            {
                if (string.IsNullOrEmpty(EncryptValue))
                {
                    EncryptKey   = Guid.NewGuid().ToString("N");
                    EncryptValue = AesEncryptionHelper.EncryptString(StringValue, EncryptKey);
                }
                StringValue = string.Empty;
            }
            return(base.ParseModel(_context, _transaction));
        }
Ejemplo n.º 5
0
        public async Task <JObject> GetAuthData(ApplicationUser user, bool rememberMe)
        {
            var rsaKeys = RSAEncryptionHelper.GenerateKeys();
            var aesKey  = AesEncryptionHelper.GenerateCombinedKeys(256);
            var token   = await GenerateAccessTokenAsync(user, rememberMe, aesKey, rsaKeys[MixConstants.CONST_RSA_PUBLIC_KEY]);

            if (token != null)
            {
                token.Info = new MixUserViewModel(user);
                await token.Info.LoadUserDataAsync();

                var plainText     = JObject.FromObject(token).ToString(Formatting.None).Replace("\r\n", string.Empty);
                var encryptedInfo = AesEncryptionHelper.EncryptString(plainText, aesKey);

                var resp = new JObject()
                {
                    new JProperty("k", aesKey),
                    new JProperty("rpk", rsaKeys[MixConstants.CONST_RSA_PRIVATE_KEY]),
                    new JProperty("data", encryptedInfo)
                };
                return(resp);
            }
            return(default);