Esempio n. 1
0
        public string[] GetCertificates(string storeName, string storeLocation)
        {
            List <string> certList = new List <string>();
            string        displayName;

            using (var store = new X509Store((StoreName)Enum.Parse(typeof(StoreName), storeName),
                                             (StoreLocation)Enum.Parse(typeof(StoreLocation), storeLocation)))
            {
                store.Open(OpenFlags.ReadOnly);
                foreach (var cert in store.Certificates)
                {
                    // try accessing private key
                    try
                    {
                        // verify access to private key for decryption
                        if (cert.HasPrivateKey)
                        {
                            // verify encryption/decryption works
                            using (EncryptionService encryptionService = GetNewEncryptionService(storeName, storeLocation, cert.Thumbprint))
                            {
                                encryptionService.Decrypt(encryptionService.Encrypt("test"));
                            }

                            displayName = !string.IsNullOrWhiteSpace(cert.FriendlyName) ? cert.FriendlyName : cert.Subject;
                            if (displayName.Length > 80)
                            {
                                displayName = displayName.Substring(0, 80) + "...";
                            }
                            certList.Add(cert.Thumbprint + " (" + displayName + ")");
                        }
                    }
                    catch (Exception) { }
                }
            }

            return(certList.ToArray());
        }
Esempio n. 2
0
        public IActionResult Login(UsersManagement.Domain.Home.Login objLogin)
        {
            string strSalt = Salt.Create();
            string hshCode = Hashing.Create("Admin@123", strSalt);

            bool IsValid = Hashing.Validate("Admin@123", strSalt, hshCode);

            //EncryptionService objEncryptionService = new EncryptionService(_dataProtProvider);
            string strEncryption = _objEncryptionService.Encrypt("Admin@123");
            string str           = _objEncryptionService.Decrypt(strEncryption);

            TokenProvider objProvider = new TokenProvider(_config);
            var           userToken   = objProvider.LoginUser(objLogin.Username, objLogin.Password);

            if (userToken != null)
            {
                //Save token in session object
                HttpContext.Session.SetString("JWToken", userToken);
                return(Redirect("~/Employee/Dashboard"));
            }
            //UsersManagement.Domain.Users.LoginViewModel objLogin = new Domain.Users.LoginViewModel();
            //var sdd = _objUser.Login("asas", "ewewe");
            return(View());
        }
Esempio n. 3
0
        public void Encryption_decryption_test(string password, string initialText)
        {
            // Arrange

            var service = new EncryptionService(_configurationService);

            var pwd = new Password(password);

            // Act

            var stream = new MemoryStream();

            service.Encrypt(pwd, initialText, stream);

            var buffer = stream.ToArray();

            stream = new MemoryStream(buffer);

            var decryptedText = service.Decrypt <string>(pwd, stream);

            // Assert

            Assert.Equal(initialText, decryptedText);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var originString = "This is some example text";

            var originBytes = System.Text.Encoding.UTF8.GetBytes(originString);

            var aes = new AesCryptoServiceProvider {
                KeySize = 256
            };

            aes.GenerateIV();
            aes.GenerateKey();
            var vectorBytes = aes.IV;
            var keyBytes    = aes.Key;

            //Not going to use these in the code, but here's how to get the values if you
            //Want to save them off.
            var vectorString = System.Text.Encoding.UTF8.GetString(vectorBytes);
            var keyString    = System.Text.Encoding.UTF8.GetString(keyBytes);

            var encryptedBytes = EncryptionService.Encrypt(keyBytes, vectorBytes, originBytes);

            var encyptedString = System.Text.Encoding.UTF8.GetString(encryptedBytes);

            var decryptedBytes = EncryptionService.Decrypt(keyBytes, vectorBytes, encryptedBytes);

            var decryptedString = System.Text.Encoding.UTF8.GetString(decryptedBytes);

            Console.WriteLine($"Origin:\t\t {originString}");
            Console.WriteLine($"Vector:\t\t {vectorString}");
            Console.WriteLine($"Key:\t\t {keyString}");
            Console.WriteLine($"Encrypted:\t {encyptedString}");
            Console.WriteLine($"Decrypted:\t {decryptedString}");

            Console.ReadLine();
        }
        private object GetObjectOfTypeFromNode(Type t, XmlNode node)
        {
            if (t.IsSimpleType())
            {
                return(GetPropertyValue(t, node));
            }

            if (t == typeof(WireEncryptedString))
            {
                if (EncryptionService != null)
                {
                    var encrypted = GetObjectOfTypeFromNode(typeof(EncryptedValue), node) as EncryptedValue;
                    var s         = EncryptionService.Decrypt(encrypted);

                    return(new WireEncryptedString {
                        Value = s
                    });
                }

                foreach (XmlNode n in node.ChildNodes)
                {
                    if (n.Name.ToLower() == "encryptedbase64value")
                    {
                        var wes = new WireEncryptedString();
                        wes.Value = GetPropertyValue(typeof(String), n) as string;

                        return(wes);
                    }
                }
            }

            if (typeof(IEnumerable).IsAssignableFrom(t))
            {
                return(GetPropertyValue(t, node));
            }

            object result = MessageMapper.CreateInstance(t);

            foreach (XmlNode n in node.ChildNodes)
            {
                Type type = null;
                if (n.Name.Contains(":"))
                {
                    type = Type.GetType("System." + n.Name.Substring(0, n.Name.IndexOf(":")), false, true);
                }

                var prop = GetProperty(t, n.Name);
                if (prop != null)
                {
                    var val = GetPropertyValue(type ?? prop.PropertyType, n);
                    if (val != null)
                    {
                        propertyInfoToLateBoundPropertySet[prop].Invoke(result, val);
                        continue;
                    }
                }

                var field = GetField(t, n.Name);
                if (field != null)
                {
                    object val = GetPropertyValue(type ?? field.FieldType, n);
                    if (val != null)
                    {
                        fieldInfoToLateBoundFieldSet[field].Invoke(result, val);
                        continue;
                    }
                }
            }

            return(result);
        }
 public void WhenCipherIsNull_ThenThrowException()
 {
     Assert.Throws <ArgumentException>(() => _sut.Decrypt(null));
 }
Esempio n. 7
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            Debug.WriteLine("Creating DB Model...");



            modelBuilder.Entity <User>().HasKey(p => p.UserId);
            modelBuilder.Entity <User>().Property(p => p.FirstName).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <User>().Property(p => p.LastName).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <User>().Property(p => p.UserName).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <User>().Property(p => p.Email).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <User>().Property(p => p.Password).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));

            modelBuilder.Entity <AuthorizationType>().Property(p => p.AuthorizationName).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <AuthorizationType>(p));
            modelBuilder.Entity <AuthorizationType>().Property(p => p.AuthorizationActive).HasConversion(p => _encryptionService.Encrypt(p), p => Convert.ToBoolean(_encryptionService.Decrypt <bool>(p)));

            modelBuilder.Entity <Phone>().Property(p => p.AreaCode).HasConversion(p => _encryptionService.Encrypt(p), p => Int32.Parse(_encryptionService.Decrypt <int>(p)));
            modelBuilder.Entity <Phone>().Property(p => p.PhoneNumber).HasConversion(p => _encryptionService.Encrypt(p), p => Int32.Parse(_encryptionService.Decrypt <int>(p)));

            modelBuilder.Entity <Address>().Property(p => p.City).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <Address>().Property(p => p.StreetOne).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <Address>().Property(p => p.StreetTwo).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <Address>().Property(p => p.State).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <Address>().Property(p => p.PostalZip).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));

            modelBuilder.Entity <DataBroker>().Property(p => p.Name).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <DataBroker>().Property(p => p.Website).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <DataBroker>().Property(p => p.VerificationType).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <DataBroker>().Property(p => p.OptOutLink).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <DataBroker>().Property(p => p.Bio).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <DataBroker>().Property(p => p.CaptureCustomerInfo).HasConversion(p => _encryptionService.Encrypt(p), p => (CapturedCustomerData)Enum.Parse(typeof(CapturedCustomerData), _encryptionService.Decrypt <Enum>(p)));
            modelBuilder.Entity <DataBroker>().Property(p => p.CustomerAccountStatus).HasConversion(p => _encryptionService.Encrypt(p), p => (Status)Enum.Parse(typeof(Status), _encryptionService.Decrypt <Enum>(p)));

            modelBuilder.Entity <EmailMarketing>().Property(p => p.MarketerName).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <EmailMarketing>().Property(p => p.Website).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <EmailMarketing>().Property(p => p.MarketerName).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <EmailMarketing>().Property(p => p.EmailMarketingStatus).HasConversion(p => _encryptionService.Encrypt(p), p => (Status)Enum.Parse(typeof(Status), _encryptionService.Decrypt <Enum>(p)));


            modelBuilder.Entity <Notification>().Property(p => p.Title).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <Notification>().Property(p => p.Description).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <Notification>().Property(p => p.Title).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <Notification>().Property(p => p.NotificationDate).HasConversion(p => _encryptionService.Encrypt(p), p => Convert.ToDateTime(_encryptionService.Decrypt <string>(p)));

            modelBuilder.Entity <PaymentInfo>().Property(p => p.CardName).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <PaymentInfo>().Property(p => p.CardNumber).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <PaymentInfo>().Property(p => p.CardType).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));
            modelBuilder.Entity <PaymentInfo>().Property(p => p.SecurityNumber).HasConversion(p => _encryptionService.Encrypt(p), p => Int32.Parse(_encryptionService.Decrypt <int>(p)));

            modelBuilder.Entity <ServicePlan>().Property(p => p.ServiceName).HasConversion(p => _encryptionService.Encrypt(p), p => _encryptionService.Decrypt <string>(p));



            //add data if in Debug
#if DEBUG
            modelBuilder.Entity <User>().HasData
            (
                new User
            {
                UserId    = 1,
                FirstName = "James",
                LastName  = "Brown",
                UserName  = "******",
                Email     = "*****@*****.**",
                Password  = "******",
            }
            );

            modelBuilder.Entity <Contact>().HasData
            (
                new Contact
            {
                ContactId = 1,
                UserId    = 1
            }

            );

            modelBuilder.Entity <Address>().HasData
            (
                new Address
            {
                AddressId = 1,
                City      = "Americus",
                State     = "GA",
                PostalZip = "31709",
                StreetOne = "123 South lee st",
                StreetTwo = "example street two",
                UserId    = 1
            }
            );

            modelBuilder.Entity <Phone>().HasData
            (
                new Phone
            {
                PhoneId     = 1,
                AreaCode    = 229,
                PhoneNumber = 5555555,
                UserId      = 1,
            }

            );

            modelBuilder.Entity <PaymentInfo>().HasData
            (
                new PaymentInfo
            {
                PaymentId      = 1,
                CardName       = "James Brown",
                CardNumber     = "123445677890",
                CardType       = "Visa",
                SecurityNumber = 299,
                UserId         = 1
            }
            );

            modelBuilder.Entity <ServicePlan>().HasData
            (
                new ServicePlan
            {
                ServicePlanId = 1,
                ServiceName   = "Basic",
                UserId        = 1
            }
            );

            modelBuilder.Entity <AuthorizationType>().HasData
            (

                new AuthorizationType {
                AuthorizationId = 1, AuthorizationName = "Email", AuthorizationActive = true, UserId = 1
            },
                new AuthorizationType {
                AuthorizationId = 2, AuthorizationName = "Phone", AuthorizationActive = true, UserId = 1
            }


            );

            modelBuilder.Entity <DataBroker>().HasData
            (

                new DataBroker
            {
                DataBrokerId        = 1,
                Name                = "Databroker One",
                Website             = "http://databrokerone.com",
                Bio                 = "Some bio information",
                VerificationType    = "Email",
                OptOutLink          = "http://optoutlink.com",
                CaptureCustomerInfo = CapturedCustomerData.Address,
                UserId              = 1,
            }

            );

            modelBuilder.Entity <EmailMarketing>().HasData
            (
                new EmailMarketing
            {
                EmailMarketingId     = 1,
                EmailMarketingStatus = Status.Active,
                MarketerName         = "Email Marketing Name Example",
                Website = "http://emailmarketersite.com",
                UserId  = 1,
            }


            );

            modelBuilder.Entity <Notification>().HasData
            (

                new Notification
            {
                NotificationId        = 1,
                Title                 = "Notification Title",
                NotificationDate      = new DateTime(),
                NotificationCompleted = false,
                UserId                = 1
            }

            );
#endif
        }
 private string Decrypt(string data, string key)
 {
     return(EncryptionService.Decrypt(data, key));
 }
    public void CallBack(string s)
    {
        //Debug.Log("CallBack s ->" + s);

        try
        {
            if (s != null && s != "")
            {
                if (msgCompress != null)
                {
                    try
                    {
                        s = msgCompress.DecompressString(s);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e);
                    }
                }

                //解密
                if (EncryptionService.IsSecret)
                {
                    s = EncryptionService.Decrypt(s);
                }

                NetWorkMessage msg = new NetWorkMessage();

                s = s.Replace(c_endCharReplaceString, c_endChar.ToString());
                Dictionary <string, object> data = Json.Deserialize(s) as Dictionary <string, object>;

                msg.m_data        = data;
                msg.m_MessageType = data["MT"].ToString();

                if (data.ContainsKey("MsgCode"))
                {
                    msg.m_MsgCode = int.Parse(data["MsgCode"].ToString());

                    if (m_msgCode != msg.m_MsgCode)
                    {
                        Debug.LogError("MsgCode error currentCode " + m_msgCode + " server code " + msg.m_MsgCode);
                        if (msg.m_MsgCode > m_msgCode)
                        {
                            m_msgCode = msg.m_MsgCode;
                            m_msgCode++;
                            m_messageCallBack(msg);
                        }
                    }
                    else
                    {
                        m_msgCode++;
                        m_messageCallBack(msg);
                    }
                }
                else
                {
                    m_messageCallBack(msg);
                }
            }
        }
        catch (Exception e)
        {
            Debug.LogError("Message error ->" + s + "<-\n" + e.ToString());
        }
    }
Esempio n. 10
0
        public virtual ActionResult ForgetPassword(FormCollection formCollection)
        {
            String KeyString = "Gv7L3V15jCdb9P5XGKiPnhHZ7JlKcmU=";
            Mail   mail      = hopeLingerieEntities.Mails.SingleOrDefault(a => a.Code == "FORGETPWD");
            var    email     = formCollection["Email"];
            var    customer  = hopeLingerieEntities.Customers.SingleOrDefault(x => x.Email == email && x.Active);

            if (customer == null)
            {
                TempData["Message"]    = "No se ha encontrado el usuario con el mail ingresado, intente nuevamente!";
                TempData["ActionType"] = ActionType.Back;

                return(Redirect("/Account/Information"));
            }

            if ((mail != null) && (!String.IsNullOrEmpty(email)))
            {
                MailService.Send(mail.From, email, mail.Subject, String.Format(mail.Body, customer.FirstName + " " + customer.LastName, email, EncryptionService.Decrypt(customer.Password, KeyString)));
            }

            TempData["Message"]    = "Los datos de ingreso al sitio han sido enviados a tu correo!";
            TempData["ActionType"] = ActionType.Catalogue;

            return(Redirect("/Account/Information"));
        }