public void TestPerfKeyGen()
        {
            int  iter = 100;
            Salt salt = new Salt();

            byte[] passbytes = Password.Encoding.GetBytes(TEST_PASSWORD);
            IPasswordDerivedBytes[] types = new IPasswordDerivedBytes[] {
                new PBKDF2(passbytes, salt, iter),
                new HashDerivedBytes <HMACMD5>(passbytes, salt, iter),
                new HashDerivedBytes <HMACSHA1>(passbytes, salt, iter),
                new HashDerivedBytes <HMACSHA256>(passbytes, salt, iter),
                new HashDerivedBytes <HMACSHA384>(passbytes, salt, iter),
                new HashDerivedBytes <HMACSHA512>(passbytes, salt, iter),
            };

            foreach (IPasswordDerivedBytes db in types)
            {
                byte[] key;

                Stopwatch w = new Stopwatch();
                w.Start();
                for (int i = 0; i < 100; i++)
                {
                    key = new PasswordKey(db, salt).CreateKey().Key;
                }
                w.Stop();

                Console.Error.WriteLine("{0,10}  {1}", w.ElapsedMilliseconds, db.GetType().Name);
            }
        }
        public void GivenContainer16bppPng_WrongDecryptionKey_ExpectedInvalidOperationExceptionThrown()
        {
            //Arrange
            string outputDirPath = Path.Combine(TestsSetUp.TempDirectory, System.Reflection.MethodBase.GetCurrentMethod().Name);

            Directory.CreateDirectory(outputDirPath);

            string containerPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Containers",
                                                "254x256_16.png");

            string secretPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Secrets",
                                             "gecon.jpg");

            var encryptionKey = new PasswordKey("9hwT5nnp");
            var decryptionKey = new PasswordKey("GhEP7vgDS");

            IStegoSystem <string, ImageStegoConstraints> stegoSystem =
                new SudokuImageStegoSystem <byte, string>(new SudokuStegoMethod256(), new SudokuByPasswordMatrixFactory <byte>(),
                                                          new Method256ImageStegoConstraints());

            string stegocontainerPath = stegoSystem.Encrypt(containerPath, secretPath, encryptionKey, outputDirPath);

            //Act & Assert
            Assert.Throws(Is.TypeOf <InvalidOperationException>()
                          .And.Message.EqualTo("Unable to extract secret data. Either the password is wrong or there is no secret data at all"),
                          () => stegoSystem.Decrypt(stegocontainerPath, decryptionKey, outputDirPath));
        }
        public void Given_Container16bppPng_UsedCapacityIsLow_ExpectedDecryptedEqualsInitialSecret()
        {
            //Arrange
            string outputDirPath = Path.Combine(TestsSetUp.TempDirectory, System.Reflection.MethodBase.GetCurrentMethod().Name);

            Directory.CreateDirectory(outputDirPath);

            string containerPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Containers",
                                                "254x256_16.png");

            string secretPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Secrets",
                                             "gecon.jpg");

            var key = new PasswordKey("aaaaaa");

            IStegoSystem <string, ImageStegoConstraints> stegoSystem =
                new SudokuImageStegoSystem <byte, string>(new SudokuStegoMethod256(), new SudokuByPasswordMatrixFactory <byte>(),
                                                          new Method256ImageStegoConstraints());

            //Act
            string stegocontainerPath = stegoSystem.Encrypt(containerPath, secretPath, key, outputDirPath);
            string restoredSecretPath = stegoSystem.Decrypt(stegocontainerPath, key, outputDirPath);

            //Assert
            //restored and initial secrets are equal
            FileAssert.AreEqual(secretPath, restoredSecretPath);
        }
        public void TestClearBytes()
        {
            byte[]      password = Encoding.UTF8.GetBytes(TEST_PASSWORD);
            PasswordKey pk1      = new PasswordKey(true, password);

            Assert.AreEqual(new byte[password.Length], password);

            password = Encoding.UTF8.GetBytes(TEST_PASSWORD);
            pk1      = new PasswordKey(false, password);
            Assert.AreEqual(Encoding.UTF8.GetBytes(TEST_PASSWORD), password);
        }
        public void TestDisposal()
        {
            string    test;
            CryptoKey key = new PasswordKey(TEST_PASSWORD);

            test = key.Encrypt("Test");
            key.Dispose();

            key.Decrypt(test);
            Assert.Fail();
        }
        public void TestUniqueDerives()
        {
            PasswordKey pk1 = new PasswordKey(TEST_PASSWORD);
            PasswordKey pk2 = new PasswordKey(TEST_PASSWORD);

            pk2.Salt = pk1.Salt;
            Assert.AreEqual(pk1.CreateKey().Key, pk2.CreateKey().Key);
            pk2.IterationCount /= 2;
            Assert.AreEqual(pk1.Salt, pk2.Salt);
            Assert.AreNotEqual(pk1.CreateKey().Key, pk2.CreateKey().Key);
        }
        public void TestSetIv()
        {
            using (PasswordKey key = new PasswordKey("bla"))
            {
                Assert.AreEqual(AESCryptoKey.ProcessDefaultIV, key.IV);
                byte[] newIv = Guid.NewGuid().ToByteArray();
                key.IV = newIv;

                Assert.AreEqual(newIv, key.IV);
                Assert.AreEqual(newIv, key.CreateKey().IV);
            }
        }
        public void TestDecodeFromNewSalt()
        {
            byte[] bytes;
            byte[] svalue = Encoding.ASCII.GetBytes("some text value");

            using (PasswordKey pk = new PasswordKey(TEST_PASSWORD))
                bytes = pk.Encrypt(svalue);

            using (PasswordKey pk = new PasswordKey(TEST_PASSWORD))
                bytes = pk.Decrypt(bytes);

            Assert.AreEqual(svalue, bytes);
        }
Example #9
0
        public void GivenContainer24bppBmp_PasswordIsNull_ExpectedArgumentExceptionThrown()
        {
            //Arrange
            string outputDirPath = TestsSetUp.TempDirectory;

            string stegocontainerPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Containers",
                                                     "158x200_24.bmp");

            var key = new PasswordKey(null);

            IStegoSystem <string, ImageStegoConstraints> stegoSystem =
                new SudokuImageStegoSystem <byte, string>(new SudokuStegoMethod256(), new SudokuByPasswordMatrixFactory <byte>(),
                                                          new Method256ImageStegoConstraints());

            //Act & Assert
            Assert.Throws(Is.TypeOf <ArgumentException>()
                          .And.Message.Contains("Wrong password format"),
                          () => stegoSystem.Decrypt(stegocontainerPath, key, outputDirPath));
        }
Example #10
0
        public void GivenEmptyStegoContainer32bppBmp_2_ExpectedInvalidOperationExceptionThrown()
        {
            //Arrange
            string outputDirPath = TestsSetUp.TempDirectory;

            string stegocontainerPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Containers",
                                                     "490x364_32.bmp");

            var key = new PasswordKey("utGpgfC");

            IStegoSystem <string, ImageStegoConstraints> stegoSystem =
                new SudokuImageStegoSystem <byte, string>(new SudokuStegoMethod256(), new SudokuByPasswordMatrixFactory <byte>(),
                                                          new Method256ImageStegoConstraints());

            //Act & Assert
            Assert.Throws(Is.TypeOf <InvalidOperationException>()
                          .And.Message.EqualTo("Unable to extract secret data. Either the password is wrong or there is no secret data at all"),
                          () => stegoSystem.Decrypt(stegocontainerPath, key, outputDirPath));
        }
        public void TestRecreate()
        {
            PasswordKey pk1 = new PasswordKey(TEST_PASSWORD);
            PasswordKey pk2 = new PasswordKey(SecureStringUtils.Create(TEST_PASSWORD));

            Assert.AreNotEqual(pk1.CreateKey().Key, pk2.CreateKey().Key);

            pk2.Salt = pk1.Salt;
            Assert.AreEqual(pk1.CreateKey().Key, pk2.CreateKey().Key);
            pk1.CreateKey();
            Assert.AreEqual(pk1.CreateKey().Key, pk2.CreateKey().Key);

            pk1.Salt = new Salt();
            Assert.AreNotEqual(pk1.Salt, pk2.Salt);
            Assert.AreNotEqual(pk1.CreateKey().Key, pk2.CreateKey().Key);
            Assert.AreEqual(pk1.CreateKey().Key, pk2.CreateKey(pk1.Salt).Key);
            pk2.Salt = pk1.Salt;
            Assert.AreEqual(pk1.Salt, pk2.Salt);
            Assert.AreEqual(pk1.CreateKey().Key, pk2.CreateKey().Key);
        }
Example #12
0
        public override int GetHashCode()
        {
            int result = 1;

            result = (result * 397) ^ (Comment != null ? Comment.GetHashCode() : 0);
            result = (result * 397) ^ (Email != null ? Email.GetHashCode() : 0);
            result = (result * 397) ^ (FailedPasswordAttemptsCount != null ? FailedPasswordAttemptsCount.GetHashCode() : 0);
            result = (result * 397) ^ (FailedPasswordAttemptWindowStart != null ? FailedPasswordAttemptWindowStart.GetHashCode() : 0);
            result = (result * 397) ^ Id.GetHashCode();
            result = (result * 397) ^ IsApproved.GetHashCode();
            result = (result * 397) ^ IsFirstTimeUser.GetHashCode();
            result = (result * 397) ^ IsLockedOut.GetHashCode();
            result = (result * 397) ^ (LastActivityDate != null ? LastActivityDate.GetHashCode() : 0);
            result = (result * 397) ^ (LastLoginDate != null ? LastLoginDate.GetHashCode() : 0);
            result = (result * 397) ^ (LastPasswordChangeDate != null ? LastPasswordChangeDate.GetHashCode() : 0);
            result = (result * 397) ^ (Password != null ? Password.GetHashCode() : 0);
            result = (result * 397) ^ (PasswordKey != null ? PasswordKey.GetHashCode() : 0);
            result = (result * 397) ^ (Username != null ? Username.GetHashCode() : 0);
            result = (result * 397) ^ UserType.GetHashCode();
            return(result);
        }
Example #13
0
        public void Given_Container8bppBmp_ExpectedArgumentExceptionThrown()
        {
            //Arrange
            string outputDirPath = TestsSetUp.TempDirectory;

            string containerPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Containers",
                                                "320x235_8.bmp");

            string secretPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Secrets",
                                             "gecon.jpg");

            var key = new PasswordKey("123456");

            IStegoSystem <string, ImageStegoConstraints> stegoSystem =
                new SudokuImageStegoSystem <byte, string>(new SudokuStegoMethod256(), new SudokuByPasswordMatrixFactory <byte>(),
                                                          new Method256ImageStegoConstraints());

            //Act & Assert
            Assert.Throws(Is.TypeOf <ArgumentException>()
                          .And.Message.EqualTo("8 bpp image is not allowed to use as container"),
                          () => stegoSystem.Encrypt(containerPath, secretPath, key, outputDirPath));
        }
Example #14
0
        public void GivenContainer24bppBmp_PasswordIsTooLong_ExpectedArgumentExceptionThrown()
        {
            //Arrange
            string outputDirPath = TestsSetUp.TempDirectory;

            string containerPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Containers",
                                                "158x200_24.bmp");

            string secretPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Secrets",
                                             "lemur.jpg");

            var key = new PasswordKey("s8uyrf7erFOefueRhiye6gUn9851tyhgyv0utMh");

            IStegoSystem <string, ImageStegoConstraints> stegoSystem =
                new SudokuImageStegoSystem <byte, string>(new SudokuStegoMethod256(), new SudokuByPasswordMatrixFactory <byte>(),
                                                          new Method256ImageStegoConstraints());

            //Act & Assert
            Assert.Throws(Is.TypeOf <ArgumentException>()
                          .And.Message.Contains("Wrong password format"),
                          () => stegoSystem.Encrypt(containerPath, secretPath, key, outputDirPath));
        }
Example #15
0
        public void Given_Container16bppPng_CapacityIsNotEnough_ExpectedInvalidOperationExceptionThrown()
        {
            //Arrange
            string outputDirPath = TestsSetUp.TempDirectory;

            string containerPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Containers",
                                                "254x256_16.png");

            string secretPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Secrets",
                                             "fox.jpg");

            var key = new PasswordKey("123456");

            IStegoSystem <string, ImageStegoConstraints> stegoSystem =
                new SudokuImageStegoSystem <byte, string>(new SudokuStegoMethod256(), new SudokuByPasswordMatrixFactory <byte>(),
                                                          new Method256ImageStegoConstraints());

            //Act & Assert
            Assert.Throws(Is.TypeOf <InvalidOperationException>()
                          .And.Message.EqualTo("Cannot encrypt secret data because container image is too small"),
                          () => stegoSystem.Encrypt(containerPath, secretPath, key, outputDirPath));
        }
        static DeveelDbConnectionStringBuilder()
        {
            defaults = new Dictionary <string, object>();
            defaults.Add(HostKey, DefaultHost);
            defaults.Add(PortKey, DefaultPort);
            defaults.Add(DatabaseKey, DefaultDatabase);
            defaults.Add(UserNameKey, DefaultUserName);
            defaults.Add(PasswordKey, DefaultPassword);
            defaults.Add(SchemaKey, DefaultSchema);
            defaults.Add(PathKey, DefaultPath);
            defaults.Add(CreateKey, DefaultCreate);
            defaults.Add(BootOrCreateKey, DefaultBootOrCreate);
            defaults.Add(ParameterStyleKey, DefaultParameterStyle);
            defaults.Add(VerboseColumnNamesKey, DefaultVerboseColumnName);
            defaults.Add(PersistSecurityInfoKey, DefaultPersistSecurityInfo);
            defaults.Add(RowCacheSizeKey, DefaultRowCacheSize);
            defaults.Add(MaxCacheSizeKey, DefaultMaxCacheSize);
            defaults.Add(FetchSizeKey, DefaultFetchSize);
            defaults.Add(MaxFetchSizeKey, DefaultMaxFetchSize);
            defaults.Add(AutoCommitKey, DefaultAutoCommit);
            defaults.Add(QueryTimeoutKey, DefaultQueryTimeout);

            keymaps = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);
            keymaps[HostKey.ToUpper()]     = HostKey;
            keymaps["ADDRESS"]             = HostKey;
            keymaps["SERVER"]              = HostKey;
            keymaps[PortKey.ToUpper()]     = PortKey;
            keymaps[DatabaseKey.ToUpper()] = DatabaseKey;
            keymaps["CATALOG"]             = DatabaseKey;
            keymaps["INITIAL CATALOG"]     = DatabaseKey;
            keymaps["DB"] = DatabaseKey;
            keymaps[SchemaKey.ToUpper()]   = SchemaKey;
            keymaps["DEFAULT SCHEMA"]      = SchemaKey;
            keymaps[PathKey.ToUpper()]     = PathKey;
            keymaps["DATA PATH"]           = PathKey;
            keymaps["DATABASE PATH"]       = PathKey;
            keymaps["DATAPATH"]            = PathKey;
            keymaps["DATABASEPATH"]        = PathKey;
            keymaps[CreateKey.ToUpper()]   = CreateKey;
            keymaps[BootOrCreateKey]       = BootOrCreateKey;
            keymaps["BOOT OR CREATE"]      = BootOrCreateKey;
            keymaps["CREATE OR BOOT"]      = BootOrCreateKey;
            keymaps["CREATEORBOOT"]        = BootOrCreateKey;
            keymaps[CreateKey.ToUpper()]   = CreateKey;
            keymaps["CREATE DATABASE"]     = CreateKey;
            keymaps[UserNameKey.ToUpper()] = UserNameKey;
            keymaps["USER"]                             = UserNameKey;
            keymaps["USER NAME"]                        = UserNameKey;
            keymaps["USER ID"]                          = UserNameKey;
            keymaps["USERID"]                           = UserNameKey;
            keymaps["UID"]                              = UserNameKey;
            keymaps[PasswordKey.ToUpper()]              = PasswordKey;
            keymaps["PASS"]                             = PasswordKey;
            keymaps["PWD"]                              = PasswordKey;
            keymaps["SECRET"]                           = PasswordKey;
            keymaps[ParameterStyleKey.ToUpper()]        = ParameterStyleKey;
            keymaps["PARAMSTYLE"]                       = ParameterStyleKey;
            keymaps["PARAMETER STYLE"]                  = ParameterStyleKey;
            keymaps["USEPARMAMETER"]                    = ParameterStyleKey;
            keymaps["USE PARAMETER"]                    = ParameterStyleKey;
            keymaps[VerboseColumnNamesKey.ToUpper()]    = VerboseColumnNamesKey;
            keymaps["VERBOSE COLUMNS"]                  = VerboseColumnNamesKey;
            keymaps["VERBOSE COLUMN NAMES"]             = VerboseColumnNamesKey;
            keymaps["VERBOSECOLUMNS"]                   = VerboseColumnNamesKey;
            keymaps["COLUMNS VERBOSE"]                  = VerboseColumnNamesKey;
            keymaps[PersistSecurityInfoKey.ToUpper()]   = PersistSecurityInfoKey;
            keymaps["PERSIST SECURITY INFO"]            = PersistSecurityInfoKey;
            keymaps[RowCacheSizeKey.ToUpper()]          = RowCacheSizeKey;
            keymaps["ROW CACHE SIZE"]                   = RowCacheSizeKey;
            keymaps["CACHE SIZE"]                       = RowCacheSizeKey;
            keymaps[MaxCacheSizeKey.ToUpper()]          = MaxCacheSizeKey;
            keymaps["MAX CACHE SIZE"]                   = MaxCacheSizeKey;
            keymaps["MAX CACHE"]                        = MaxCacheSizeKey;
            keymaps[QueryTimeoutKey.ToUpper()]          = QueryTimeoutKey;
            keymaps["QUERY TIMEOUT"]                    = QueryTimeoutKey;
            keymaps[IgnoreIdentifiersCaseKey.ToUpper()] = IgnoreIdentifiersCaseKey;
            keymaps["IGNORE CASE"]                      = IgnoreIdentifiersCaseKey;
            keymaps["IGNORE ID CASE"]                   = IgnoreIdentifiersCaseKey;
            keymaps["ID CASE IGNORED"]                  = IgnoreIdentifiersCaseKey;
            keymaps[StrictGetValueKey.ToUpper()]        = StrictGetValueKey;
            keymaps["STRICT"]                           = StrictGetValueKey;
            keymaps["STRICT GETVALUE"]                  = StrictGetValueKey;
            keymaps["STRICT VALUE"]                     = StrictGetValueKey;
            keymaps["STRICTVALUE"]                      = StrictGetValueKey;
            keymaps[FetchSizeKey.ToUpper()]             = FetchSizeKey;
            keymaps["FETCH SIZE"]                       = FetchSizeKey;
            keymaps["ROW COUNT"]                        = FetchSizeKey;
            keymaps["ROWCOUNT"]                         = FetchSizeKey;
            keymaps[MaxFetchSizeKey.ToUpper()]          = MaxFetchSizeKey;
            keymaps["MAX FETCH SIZE"]                   = MaxFetchSizeKey;
            keymaps["MAXFETCHSIZE"]                     = MaxFetchSizeKey;
            keymaps["MAX ROW COUNT"]                    = MaxFetchSizeKey;
            keymaps["MAX ROWCOUNT"]                     = MaxFetchSizeKey;
            keymaps["MAXROWCOUNT"]                      = MaxFetchSizeKey;
            keymaps[AutoCommitKey.ToUpper()]            = AutoCommitKey;
            keymaps["AUTOCOMMIT"]                       = AutoCommitKey;
            keymaps["AUTO-COMMIT"]                      = AutoCommitKey;
            keymaps["AUTO_COMMIT"]                      = AutoCommitKey;
            keymaps["AUTO COMMIT"]                      = AutoCommitKey;
            keymaps["COMMIT AUTO"]                      = AutoCommitKey;
            keymaps["COMMIT_AUTO"]                      = AutoCommitKey;
            keymaps["COMMITAUTO"]                       = AutoCommitKey;
            keymaps["COMMIT-AUTO"]                      = AutoCommitKey;
            keymaps["COMMIT"]                           = AutoCommitKey;
            keymaps["ENLIST"]                           = EnlistKey;
        }