public ActionResult CreateCharity(string id, string password)
        {
            var encryptor = new Encryptor();
            password = encryptor.Encrypt(password);

            var charity = new Charity
                {
                    CharityId = id,
                    Password = password,
                    Address1 = "__",
                    Address2 = "__",
                    City = "__",
                    State = "__",
                    PostalCode = "__",
                    Essay = "__",
                    Email = "__",
                    FirstName = "__",
                    IsSearchable = false,
                    LastName = "__",
                    OrganizationName = "charity" + id,
                    Phone = "__",
                    Website = "__",
                    YearsService = 0
                };

            _charityRepository.Add(charity);

            return Json(new { awesome = "clearly true" });
        }
        private void performEncryptionTest(string functionName, string plaintext, string password)
        {
            Encryptor cryptor = new Encryptor();
            string encrypted = cryptor.Encrypt(plaintext, password);

            this.reportSuccess(functionName, encrypted != "" && encrypted != plaintext);
        }
        public ActionResult New(CharityContainerViewModel vm)
        {
            vm.Charity.CharityId = LoggedInUser.CharityId;

            if (string.IsNullOrWhiteSpace(vm.Charity.Password))
            {
                ModelState.AddModelError("Charity.Password", "You must select a password");
            }

            if (ModelState.IsValid)
            {
                var encryptor = new Encryptor();
                vm.Charity.Password = encryptor.Encrypt(vm.Charity.Password);
                var result = _charityUpdater.Update(vm.Charity, vm.SelectedSkills, vm.SelectedAreas);

                switch (result)
                {
                    case UpdateResult.Successful:
                        return RedirectTo.Search.BoardMembers();
                    case UpdateResult.ItemAlreadyExists:
                        ModelState.AddModelError("OrganizationName", "An organization with that name already exists.");
                        break;
                }
            }

            vm.SelectedSkills = Enum.GetValues(typeof(Skill)).OfType<Skill>().ToList();
            vm.SelectedAreas = Enum.GetValues(typeof(ServiceArea)).OfType<ServiceArea>().ToList();
            vm.CurrentAreas = new List<ServiceAreaEntity>();
            vm.CurrentSkills = new List<SkillEntity>();

            return View(vm);
        }
示例#4
0
 /// <summary> Wraps the stream with a cryptographic stream </summary>
 public sealed override Stream Encrypt(Stream stream)
 {
     try
     {
         ICryptoTransform xform = new Encryptor(this, BlockSize, TransformSize);
         return new DisposingStream(new CryptoStream(stream, xform, CryptoStreamMode.Write))
             .WithDisposeOf(xform);
     }
     catch (InvalidOperationException) { throw; }
     catch { throw CryptographicException(); }
 }
示例#5
0
			public void Returns_InitializationVector()
			{
				using (SymmetricAlgorithm algorithm = TestObjectFactory.CreateAlgorithm())
				{
					Console.Write("algorithm.Key: ");
					Console.WriteLine(algorithm.Key.ToBase64String(true));
					Console.Write("algorithm.Key.Length: ");
					Console.WriteLine(algorithm.Key.Length);
					Console.Write("algorithm.IV: ");
					Console.WriteLine(algorithm.IV.ToBase64String(true));
					Console.Write("algorithm.IV.Length: ");
					Console.WriteLine(algorithm.IV.Length);

					byte[] encryptionKey = TestObjectFactory.CreateEncryptionKey();
					byte[] initializationVector;
					using (Encryptor encryptor = new Encryptor(
						algorithm, encryptionKey, out initializationVector, EncryptionOptions.AllowNullInput))
					{
						Console.WriteLine();
						Console.Write("encryptionKey: ");
						Console.WriteLine(encryptionKey.ToBase64String(true));

						Console.WriteLine();
						Console.Write("algorithm.Key: ");
						Console.WriteLine(algorithm.Key.ToBase64String(true));
						////Console.Write("encryptor.EncryptionKey: ");
						////Console.WriteLine(encryptor.EncryptionKey.ToBase64String(true));

						Console.WriteLine();
						Console.Write("algorithm.IV: ");
						Console.WriteLine(algorithm.IV.ToBase64String(true));
						Console.Write("encryptor.InitializationVector: ");
						Console.WriteLine(initializationVector.ToBase64String(true));
					}
				}

				////	using (Encryptor<SymmetricAlgorithm> encryptor = TestObjectFactory.CreateEncryptor())
				////	{
				////		
				////	}
			}
 public void CanCompute()
 {
     string result = new Encryptor().Encrypt("12345");
     Assert.AreEqual("foo", result);
 }
        private void performEncryptionTestWithSchemaCheck(string functionName, string plaintext, string password, Schema schemaVersion)
        {
            Encryptor cryptor = new Encryptor();
            string encryptedB64 = cryptor.Encrypt(plaintext, password, schemaVersion);
            byte[] encrypted = Convert.FromBase64String(encryptedB64);

            Schema actualSchemaVersion = (Schema)encrypted[0];
            this.reportSuccess(functionName, actualSchemaVersion == schemaVersion);
        }
        private void performEncryptionTestWithExplicitSchema(string functionName, string plaintext, string password, Schema schemaVersion)
        {
            Encryptor cryptor = new Encryptor();
            string encrypted = cryptor.Encrypt(plaintext, password, schemaVersion);

            this.reportSuccess(functionName, encrypted != "" && encrypted != plaintext);
        }
        private void testCannotUseWithUnsupportedSchemaVersions()
        {
            Encryptor encryptor = new Encryptor();
            string encryptedB64 = encryptor.Encrypt(TestStrings.SAMPLE_PLAINTEXT, TestStrings.SAMPLE_PASSWORD_A);

            byte[] encrypted = Convert.FromBase64String(encryptedB64);
            encrypted[0] = 0x03;
            string encryptedV3 = Convert.ToBase64String(encrypted);

            Decryptor decryptor = new Decryptor();
            string decrypted = decryptor.Decrypt(encryptedV3, TestStrings.SAMPLE_PASSWORD_A);

            this.reportSuccess(MethodBase.GetCurrentMethod().Name, decrypted == "");
        }
示例#10
0
        private void performSymmetricTestWithExplicitSchema(string functionName, string plaintext, string password, Schema schemaVersion)
        {
            Encryptor encryptor = new Encryptor();
            string encryptedB64 = encryptor.Encrypt(plaintext, password, schemaVersion);

            Decryptor decryptor = new Decryptor();
            string decrypted = decryptor.Decrypt(encryptedB64, password);

            this.reportSuccess(functionName, decrypted == plaintext);
        }
示例#11
0
        private void performSymmetricTest(string functionName, string plaintext, string password)
        {
            Encryptor encryptor = new Encryptor();
            string encryptedB64 = encryptor.Encrypt(plaintext, password);

            Decryptor decryptor = new Decryptor();
            string decrypted = decryptor.Decrypt(encryptedB64, password);

            this.reportSuccess(functionName, decrypted == plaintext);
        }
示例#12
0
 public EncryptorFactoryImpl()
 {
     _defaultEncryptor = new EncryptorImpl();
 }
        public ActionResult Edit(CharityContainerViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var charity = vm.Charity;
                charity.CharityId = LoggedInUser.CharityId;

                var encryptor = new Encryptor();
                charity.Password = encryptor.Encrypt(charity.Password);
                var result = _charityUpdater.Update(charity, vm.SelectedSkills, vm.SelectedAreas);

                switch (result)
                {
                    case UpdateResult.Successful:
                        return RedirectTo.Search.BoardMembers();
                    case UpdateResult.ItemAlreadyExists:
                        ModelState.AddModelError("OrganizationName", "An organization with that name already exists.");
                        break;
                }
            }

            return View(vm);
        }
示例#14
0
 public static string Decrypt64(this string str, string secret, CryptoProviderType provider = CryptoProviderType.TripleDES, CipherMode cipherMode = CipherMode.ECB, PaddingMode paddingMode = PaddingMode.Zeros, byte[] IV = null)
 {
     return(Encryptor.Decrypt64(str, secret, provider, cipherMode, paddingMode, IV));
     //return ASCIIEncoding.ASCII.GetString(Encryptor.Decrypt(str.Decode64ToByteArray(), secret, provider, cipherMode, paddingMode)).Replace("\0","");
 }
示例#15
0
 public static byte[] Decrypt(this string str, string secret, CryptoProviderType provider = CryptoProviderType.TripleDES, CipherMode cipherMode = CipherMode.ECB, PaddingMode paddingMode = PaddingMode.Zeros, byte[] IV = null)
 {
     return(Encryptor.Decrypt(str.ToByteArray(), secret, provider, cipherMode, paddingMode, IV));
 }
        public ActionResult Login(LoginViewModel vm)
        {
            var encryptor = new Encryptor();
            if (!String.IsNullOrEmpty(vm.BoardPassword))
                vm.BoardPassword = encryptor.Encrypt(vm.BoardPassword);
            if (!String.IsNullOrWhiteSpace(vm.CharityPassword))
                vm.CharityPassword = encryptor.Encrypt(vm.CharityPassword);

            if (ModelState.IsValid)
            {
                ActionResult result = null;
                string ticket = null;

                if (vm.Type == "board")
                {
                    var boardMemberId = _boardMemberRepository.ValidateLogin(vm.BoardEmail, vm.BoardPassword);

                    if (!boardMemberId.HasValue)
                    {
                        ModelState.AddModelError("BoardPassword", "Invalid login.");
                        return View(vm);
                    }

                    ticket = _formsAuth.SignIn(vm.BoardEmail, UserAuthenticationType.Board, string.Empty, boardMemberId);

                    var boardMember = _boardMemberRepository.GetBoardMember(boardMemberId.Value);

                    if (boardMemberId == null)
                    {
                        result = RedirectTo.BoardMember.New();
                    }
                    else
                    {
                        result = RedirectTo.Search.NonProfits();
                    }
                }
                else
                {
                    var charityId = _charityRepository.ValidateLogin(vm.CharityUsername, vm.CharityPassword);

                    if (string.IsNullOrWhiteSpace(charityId))
                    {
                        ModelState.AddModelError("CharityPassword", "Invalid login.");
                        return View(vm);
                    }

                    if (vm.CharityUsername == "61903")
                        ticket = _formsAuth.SignIn(vm.CharityUsername, UserAuthenticationType.UberMegaSuperUltraUser, charityId, null);
                    else
                        ticket = _formsAuth.SignIn(vm.CharityUsername, UserAuthenticationType.Charity, charityId, null);

                    var charity = _charityRepository.GetSpecificCharity(x => x.CharityId == charityId);

                    if (charity == null)
                        result = RedirectTo.NonProfit.New();
                    else
                    {
                        result = RedirectTo.Search.BoardMembers();
                    }
                }

                var cookie = new HttpCookie(FormsAuthFacade.COOKIE_NAME, ticket);
                cookie.Expires = DateTime.Now.AddDays(30);
                Response.Cookies.Add(cookie);
                return result;
            }

            return View(vm);
        }