Beispiel #1
0
        public ResultInfo Find(string userAccount, string password)
        {
            var resultInfo = new ResultInfo();

            resultInfo.Succeeded = false;
            resultInfo.Result    = Repository.Get(u => u.Email == userAccount);
            var usuario = (Usuario)resultInfo.Result;

            if (usuario != null)
            {
                resultInfo.Succeeded = (usuario.Password == _cryptoManager.Encrypt(password));
            }

            usuario.Password = "******";//
            if (resultInfo.Succeeded)
            {
                resultInfo.Result = new UserSettings()
                {
                    Usuario = usuario,
                    //UserRoleOptions = UserMenu.GetMenu(usuario.Role)
                };
            }
            else
            {
                resultInfo.Result = new UserSettings();
            }

            return(resultInfo);
        }
Beispiel #2
0
        /// <summary>
        /// Log-in
        /// </summary>
        /// <param name="userAccount"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ResultInfo Find(string userAccount, string password)
        {
            var resultInfo = new ResultInfo();

            resultInfo.Succeeded = false;
            resultInfo.Result    = Repository.Get(u => u.Cuenta == userAccount);
            var usuario = (UsuarioPublico)resultInfo.Result;

            if (usuario != null)
            {
                resultInfo.Succeeded = (usuario.Pwd == _cryptoManager.Encrypt(password));
                usuario.Pwd          = "(O)^(_)";//
            }

            if (resultInfo.Succeeded)
            {
                resultInfo.Result = usuario;
            }
            else
            {
                resultInfo.Result = new UsuarioPublico();
            }

            return(resultInfo);
        }
Beispiel #3
0
        public Task SaveConnectionProperty(ConnectionProperties connectionProperties)
        {
            if (connectionProperties.IsPasswordEncrypted)
            {
                connectionProperties.Password = _cryptoManager.Encrypt(connectionProperties.Password);
            }

            return(_work.ConnectionPropertiesRepository.Insert(connectionProperties));
        }
        public static void EncryptField(this JObject jsonJObject, ICryptoManager cryptoManager, string path)
        {
            var jToken    = jsonJObject.SelectToken(path);
            var rawBytes  = Encoding.UTF8.GetBytes(jToken.ToString());
            var encrypted = cryptoManager.Encrypt(rawBytes);

            jsonJObject.Property(path).Remove();
            jsonJObject.Add(new JProperty(cryptoManager.Mangle(path), encrypted.ToJObject()));
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var rawJson   = JsonConvert.SerializeObject(value, SerializerSettings);
            var plainText = Encoding.UTF8.GetBytes(rawJson);

            var encryptionResult = _cryptoManager.Encrypt(plainText);
            var token            = encryptionResult.ToJObject();

            token.WriteTo(writer);
        }
        public void Write(string configString)
        {
            if (File.Exists(_configPath))
            {
                File.Delete(_configPath);
            }

            string       textContent  = _cryptoManager.Encrypt(configString);
            UTF8Encoding utf8Encoding = new UTF8Encoding(true);

            byte[] buffer = utf8Encoding.GetBytes(textContent);
            using (FileStream fileStream = File.OpenWrite(_configPath))
            {
                fileStream.Write(buffer, 0, buffer.Length);
            }

            File.SetAttributes(_configPath, FileAttributes.Hidden);
        }
        internal static byte[] Decrypt(this JObject encrypted, ICryptoManager cryptoManager, string signingKeyName)
        {
#pragma warning disable 618
            var sig = encrypted.SelectToken(EncryptionField.Signature).Value <string>();
#pragma warning restore 618
            var ciphertext = encrypted.SelectToken(EncryptionField.CipherText).Value <string>();
            var alg        = encrypted.SelectToken(EncryptionField.Algorithm).Value <string>();
#pragma warning disable 618
            var iv = encrypted.SelectToken(EncryptionField.InitializationVector).Value <string>();
#pragma warning restore 618
            var kid = encrypted.SelectToken(EncryptionField.KeyIdentifier).Value <string>();

            var kidBytes    = Encoding.UTF8.GetBytes(kid);
            var algBytes    = Encoding.UTF8.GetBytes(alg);
            var ivBytes     = Convert.FromBase64String(iv);
            var cipherBytes = Convert.FromBase64String(ciphertext);

            var buffer = new byte[kidBytes.Length + algBytes.Length + ivBytes.Length + cipherBytes.Length];
            Buffer.BlockCopy(kidBytes, 0, buffer, 0, kidBytes.Length);
            Buffer.BlockCopy(algBytes, 0, buffer, kidBytes.Length, algBytes.Length);
            Buffer.BlockCopy(ivBytes, 0, buffer, kidBytes.Length + algBytes.Length, ivBytes.Length);
            Buffer.BlockCopy(cipherBytes, 0, buffer, kidBytes.Length + algBytes.Length + ivBytes.Length, cipherBytes.Length);

            var signature = cryptoManager.Encrypt(buffer, signingKeyName);
            if (sig != signature.Ciphertext)
            {
                throw new DecryptionFailureException();
            }

            return(cryptoManager.Decrypt(new EncryptionResult
            {
                Alg = alg,
                Kid = kid,
                Ciphertext = ciphertext,
                Iv = Convert.FromBase64String(iv)
            }));
        }