Exemplo n.º 1
0
        public void Generate_Should_Return_Password_Of_Specified_Length()
        {
            var generator = new PronounceablePasswordGenerator();

            Assert.Equal(5, generator.Generate(5).Length);
            Assert.Equal(6, generator.Generate(6).Length);
            Assert.Equal(10, generator.Generate(10).Length);
            Assert.Equal(30, generator.Generate(30).Length);
        }
Exemplo n.º 2
0
        public void Generate_Must_Generate_MaxCount_Passwords_If_Count_Is_Greater_Than_MaxCount()
        {
            // Arrange
            var generator = new PronounceablePasswordGenerator();

            // Act
            var password = generator.Generate(100, 4, 8);

            // Assert
            Assert.Equal(PronounceablePasswordGenerator.MaxCount, password.Count());
        }
Exemplo n.º 3
0
        public void Generate_Must_Generate_1_Password_If_Count_Is_Less_Than_1()
        {
            // Arrange
            var generator = new PronounceablePasswordGenerator();

            // Act
            var password = generator.Generate(0, 4, 8);

            // Assert
            Assert.Single(password);
        }
Exemplo n.º 4
0
        public void Must_not_generate_a_password_longer_than_MaxLength()
        {
            // Arrange
            var generator = new PronounceablePasswordGenerator();

            // Act
            var password = generator.Generate(100);

            // Assert
            Assert.Equal(PronounceablePasswordGenerator.MaxLength, password.Length);
        }
        public void Should_not_generate_a_duplicate_8_character_password_in_1000_Iterations()
        {
            const Int32 iterations = 1000;

            // Arrange
            var generator = new PronounceablePasswordGenerator();

            // Act 100000 times
            var set = new HashSet <String>();

            for (var index = 0; index < iterations; index++)
            {
                Assert.True(set.Add(generator.Generate(8)));
            }
        }
Exemplo n.º 6
0
        private void GenerateKeys(decimal keySize, decimal numberOfKeys)
        {
            StringBuilder keys = new StringBuilder();

            for (int i = 1; i < numberOfKeys + 1; i++)
            {
                string key;
                if (chkCreatepronounceablepasswords.Checked)
                {
                    key = PronounceablePasswordGenerator.Generate((int)keySize);
                }
                else
                {
                    key = SymmetricCryptoProvider.GenerateKeyPhrase((int)keySize).TrimEnd(Convert.ToChar("="));
                }

                int groupSize = (int)numGroupSize.Value;

                if (chkGroupIntoPairs.Checked && groupSize > 0)
                {
                    string groupedKey = "";

                    for (int j = 0; j < key.Length; j++)
                    {
                        groupedKey += key[j];

                        if ((j + 1) % groupSize == 0)
                        {
                            groupedKey += "-";
                        }
                    }

                    groupedKey = groupedKey.TrimEnd('-');

                    keys.AppendLine(string.Format("{0}, {1}", i, groupedKey));
                }
                else
                {
                    keys.AppendLine(string.Format("{0}, {1}", i, key));
                }
            }

            txtkeys.Text = keys.ToString();
        }
Exemplo n.º 7
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            SymmetricCryptoProvider symmetricCrypt = new SymmetricCryptoProvider();

            string password = txtPassphrase.Text;

            if (string.IsNullOrWhiteSpace(password))
            {
                password = PronounceablePasswordGenerator.Generate(10);
                MessageBox.Show(
                    string.Format("Your random password is {0}.  \r Please copy it now then click OK.", password),
                    "Password generated", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            string cypertext = symmetricCrypt.EncryptWithKey(txtClearText.Text, password);

            txtCypertext.Text = cypertext;

            tabControl1.SelectTab(1);
        }
Exemplo n.º 8
0
        public ActionResult CreateKey(NewKeyModel newKeyModel)
        {
            if (string.IsNullOrWhiteSpace(newKeyModel.Passphrase))
            {
                ViewBag.Passphrase         =
                    newKeyModel.Passphrase = PronounceablePasswordGenerator.Generate(14);
            }
            else
            {
                ViewBag.Passphrase = "*******";
            }

            var request = CryptoKey.CreateRequestWithPassPhrase(newKeyModel.Passphrase);

            request.LockDate = newKeyModel.LockDate;
            if (newKeyModel.ReleaseDate != null)
            {
                request.ReleaseDate = (DateTime)newKeyModel.ReleaseDate;
            }
            request.DeleteKeyAfterReading      = newKeyModel.DeleteKeyAfterReading;
            request.DeleteMessagesAfterReading = newKeyModel.DeleteMessagesAfterReading;

            if (!string.IsNullOrWhiteSpace(newKeyModel.NotifyEmail))
            {
                request.Notifications.Add(new Notification()
                {
                    Email = newKeyModel.NotifyEmail
                });
            }

            if (newKeyModel.LockDate == null)
            {
                newKeyModel.LockDate = DateTime.Now.AddDays(30);
            }
            requestRepository.AddRequest(request);
            return(View("NewKeyDetails", request));
        }
Exemplo n.º 9
0
        public ActionResult Send(SelfDestructingMessageModel message)
        {
            // verify email

            if (!Domain.Validation.IsValidEmail(message.Email))
            {
                throw new ArgumentException("email", "invalid email format");
            }


            string passphrase = PronounceablePasswordGenerator.Generate(32);

            passphrase = HttpUtility.UrlEncode(passphrase);

            int messageId = selfDestructingMessageRepository.StoreMessage(new SelfDestructingMessage()
            {
                Message = message.MessageText
            },
                                                                          passphrase,
                                                                          message.AttachmentName,
                                                                          message.Attachment);

            string hash = SymmetricCryptoProvider.GetSecureHashForString(message.MessageText);

            const string notification = @"
Hello,

You have received a self-destructing message.  This message will be decrypted and erased when you open the link below.

You can read it at 

https://{0}:{1}/selfdestruct/read/?messageId={2}&passphrase={3}&hash={4}


CryptAByte.com is not responsible for the contents of messages.  For more information, please visit https://CryptAByte.com/SelfDestruct
";

            MailMessage mailMessage = new MailMessage {
                From = new MailAddress("*****@*****.**")
            };

            mailMessage.To.Add(new MailAddress(message.Email));

            mailMessage.Subject = "New self-destructing message @ CryptAByte";

            if (Request == null)
            {
                string messageText = string.Format(notification, "cryptabyte.com", 443, messageId, passphrase, hash);

                Debug.WriteLine(messageText);

                mailMessage.Body = messageText;
            }
            else
            {
                mailMessage.Body = string.Format(notification, Request.Url.Host, Request.Url.Port, messageId, passphrase, hash);;
            }

            SmtpClient client = new SmtpClient();

            client.Send(mailMessage);

            return(Content("Message sent"));
        }