Esempio n. 1
0
        public void StressTestStringEncryptionUniqueness()
        {
            Dictionary <string, string> results = new Dictionary <string, string>();


            int           times       = 1000;
            Random        r           = new Random();
            List <string> randomInput = GetRandomStrings(times, 20, char.MinValue, char.MaxValue);

            for (int i = 0; i < times; i++)
            {
                var plain = randomInput[i];

                var enc = FPEWrapper.EncryptString(key, tweak, plain);
                var dec = FPEWrapper.DecryptString(key, tweak, enc);
                Console.WriteLine($"Src:{enc}, Dest:{dec}");
                Assert.AreEqual(plain, dec);
                Assert.AreEqual(plain.Length, dec.Length);

                if (results.ContainsKey(enc))
                {
                    Assert.Fail($"results already contains Encrypted value:{enc} for Plain text:{results[enc]}");
                }
                else
                {
                    results.Add(enc, plain);
                }
            }
        }
Esempio n. 2
0
        public void TestSafeIntEncryptionMinusOne()
        {
            int initial        = -1;
            var encryptedValue = FPEWrapper.EncryptSafeInt(key, tweak, initial);
            var decryptedValue = FPEWrapper.DecryptSafeInt(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
Esempio n. 3
0
        public void TestIntEncryptionMaxMinusTwo()
        {
            int initial        = int.MaxValue - 2;
            var encryptedValue = FPEWrapper.EncryptInt(key, tweak, initial);
            var decryptedValue = FPEWrapper.DecryptInt(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
Esempio n. 4
0
        public void TestIntToIntRankingMinPlusOne()
        {
            int initial       = FPEWrapper.MinAllowedSafeInt + 1;
            var rankedValue   = FPEWrapper.RankIntToSafeInt(initial);
            var unrankedValue = FPEWrapper.UnrankSafeIntToInt(rankedValue);

            Assert.AreEqual(initial, unrankedValue);
        }
Esempio n. 5
0
        public void TestSafeIntEncryptionMinPlusTwo()
        {
            int initial        = FPEWrapper.MinAllowedSafeInt + 2;
            var encryptedValue = FPEWrapper.EncryptSafeInt(key, tweak, initial);
            var decryptedValue = FPEWrapper.DecryptSafeInt(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
Esempio n. 6
0
        public void TestRankingLongZero()
        {
            long initial       = 0;
            var  rankedValue   = FPEWrapper.RankLong(initial);
            var  unrankedValue = FPEWrapper.UnrankLong(rankedValue);

            Assert.AreEqual(initial, unrankedValue);
        }
Esempio n. 7
0
        public void TestDecimalEncryptionMinusOne()
        {
            Decimal initial        = -1;
            var     encryptedValue = FPEWrapper.EncryptDecimal(key, tweak, initial);
            var     decryptedValue = FPEWrapper.DecryptDecimal(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
Esempio n. 8
0
        public void TestRankingMinPlusOne()
        {
            int initial       = int.MinValue + 1;
            var rankedValue   = FPEWrapper.RankInt(initial);
            var unrankedValue = FPEWrapper.UnrankInt(rankedValue);

            Assert.AreEqual(initial, unrankedValue);
        }
Esempio n. 9
0
        public void TestDecimalEncryptionMinPlusTwo()
        {
            Decimal initial        = FPEWrapper.MinAllowedDecimal + 0.00002M;
            var     encryptedValue = FPEWrapper.EncryptDecimal(key, tweak, initial);
            var     decryptedValue = FPEWrapper.DecryptDecimal(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
Esempio n. 10
0
        public void TestIntToIntRankingZero()
        {
            int initial       = 0;
            var rankedValue   = FPEWrapper.RankIntToSafeInt(initial);
            var unrankedValue = FPEWrapper.UnrankSafeIntToInt(rankedValue);

            Assert.AreEqual(initial, unrankedValue);
        }
Esempio n. 11
0
        public void TestLongEncryptionMinPlusTwo()
        {
            long initial        = long.MinValue + 2;
            var  encryptedValue = FPEWrapper.EncryptLong(key, tweak, initial);
            var  decryptedValue = FPEWrapper.DecryptLong(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
Esempio n. 12
0
        public void TestLongEncryptionZero()
        {
            long initial        = 0;
            var  encryptedValue = FPEWrapper.EncryptLong(key, tweak, initial);
            var  decryptedValue = FPEWrapper.DecryptLong(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
Esempio n. 13
0
        public void TestRankingLongMinPlusOne()
        {
            long initial       = long.MinValue + 1;
            var  rankedValue   = FPEWrapper.RankLong(initial);
            var  unrankedValue = FPEWrapper.UnrankLong(rankedValue);

            Assert.AreEqual(initial, unrankedValue);
        }
Esempio n. 14
0
        public void TestDecimalEncryptionFiveDecimalPoints()
        {
            Decimal initial        = 0.00001M;
            var     encryptedValue = FPEWrapper.EncryptDecimal(key, tweak, initial);
            var     decryptedValue = FPEWrapper.DecryptDecimal(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
Esempio n. 15
0
        public void TestSqlDateEncryption2()
        {
            var plain = new DateTime(1984, 10, 1);

            DateTime enc = FPEWrapper.EncryptSqlDateTime(key, tweak, plain);
            DateTime dec = FPEWrapper.DecryptSqlDateTime(key, tweak, enc);

            Assert.AreEqual(plain, dec);
        }
Esempio n. 16
0
        public void TestSqlDateEncryption()
        {
            var plain = DateTime.Now;

            DateTime enc = FPEWrapper.EncryptSqlDateTime(key, tweak, plain);
            DateTime dec = FPEWrapper.DecryptSqlDateTime(key, tweak, enc);

            Assert.AreEqual(plain, dec);
        }
Esempio n. 17
0
        public void TestULongEncryptionMin()
        {
            ulong plain = ulong.MinValue + 1;

            var enc = FPEWrapper.EncryptULong(key, tweak, plain);
            var dec = FPEWrapper.DecryptULong(key, tweak, enc);

            Assert.AreEqual(plain, dec);
        }
Esempio n. 18
0
        public void TestUIntEncryptionZero()
        {
            uint plain = 0;

            var enc = FPEWrapper.EncryptUInt(key, tweak, plain);
            var dec = FPEWrapper.DecryptUInt(key, tweak, enc);

            Assert.AreEqual(plain, dec);
        }
Esempio n. 19
0
        public void TestSqlDateEncryptionMax()
        {
            var plain = FPEWrapper.MaxPossibleSqlDate;

            DateTime enc = FPEWrapper.EncryptSqlDateTime(key, tweak, plain);
            DateTime dec = FPEWrapper.DecryptSqlDateTime(key, tweak, enc);

            Assert.AreEqual(plain, dec);
        }
Esempio n. 20
0
        public void TestUIntEncryptionMin()
        {
            uint plain = uint.MinValue + 1;

            var enc = FPEWrapper.EncryptUInt(key, tweak, plain);
            var dec = FPEWrapper.DecryptUInt(key, tweak, enc);

            Assert.AreEqual(plain, dec);
        }
Esempio n. 21
0
        public void TestStringEncryption()
        {
            var plain = "hello world";

            var enc = FPEWrapper.EncryptString(key, tweak, plain);

            var dec = FPEWrapper.DecryptString(key, tweak, enc);

            Assert.AreEqual(plain, dec);
            Assert.AreEqual(plain.Length, dec.Length);
        }
Esempio n. 22
0
        public void TestStringEncryptionUniqueness()
        {
            Dictionary <string, string> results = new Dictionary <string, string>();


            List <string> randomInput = new List <string>()
            {
                "01",
                "02",
                "03",
                "04",
                "05",
                "06",
                "07",
                "08",
                "09",
                "1",
                "10",
                "11",
                "12",
                "13",
                "14",
                "15",
                "16",
                "17",
                "18",
                "19",
                "99",
                "Demo"
            };

            for (int i = 0; i < randomInput.Count; i++)
            {
                var plain = randomInput[i];

                var enc = FPEWrapper.EncryptString(key, tweak, plain);
                var dec = FPEWrapper.DecryptString(key, tweak, enc);
                Console.WriteLine($"Src:{enc}, Dest:{dec}");
                Assert.AreEqual(plain, dec);
                Assert.AreEqual(plain.Length, dec.Length);

                if (results.ContainsKey(enc))
                {
                    Assert.Fail($"results already contains Encrypted value:{enc} for Plain text:{results[enc]}");
                }
                else
                {
                    results.Add(enc, plain);
                }
            }
        }
Esempio n. 23
0
        public void StressTestSafeIntEncryption()
        {
            Random r     = new Random();
            int    times = 10000;

            for (int i = 0; i < times; i++)
            {
                int plain          = r.Next(FPEWrapper.MinAllowedSafeInt, FPEWrapper.MaxAllowedSafeInt);
                var encryptedValue = FPEWrapper.EncryptSafeInt(key, tweak, plain);
                var decryptedValue = FPEWrapper.DecryptSafeInt(key, tweak, encryptedValue);
                Console.WriteLine($"Src:{plain}, Dest:{decryptedValue}");
                Assert.AreEqual(plain, decryptedValue);
            }
        }
Esempio n. 24
0
        public void StressTestDecimalEncryption()
        {
            Random r     = new Random();
            int    times = 10000;

            for (int i = 0; i < times; i++)
            {
                Decimal plain = r.Next(int.MinValue + 2, int.MaxValue - 2);
                var     enc   = FPEWrapper.EncryptDecimal(key, tweak, plain);
                var     dec   = FPEWrapper.DecryptDecimal(key, tweak, enc);
                Console.WriteLine($"Src:{enc}, Dest:{dec}");
                Assert.AreEqual(plain, dec);
            }
        }
Esempio n. 25
0
        public void TestULongEncryptionRandom()
        {
            Random r     = new Random();
            int    times = 1000;

            for (int i = 0; i < times; i++)
            {
                ulong plain = (ulong)r.Next(0, int.MaxValue);

                var enc = FPEWrapper.EncryptULong(key, tweak, plain);
                var dec = FPEWrapper.DecryptULong(key, tweak, enc);

                Assert.AreEqual(plain, dec);
            }
        }
Esempio n. 26
0
        public void StressTestStringEncryption()
        {
            Random r     = new Random();
            int    times = 1000;

            for (int i = 0; i < times; i++)
            {
                var plain = GetRandomString(20);

                var enc = FPEWrapper.EncryptString(key, tweak, plain);
                var dec = FPEWrapper.DecryptString(key, tweak, enc);
                Console.WriteLine($"Src:{enc}, Dest:{dec}");
                Assert.AreEqual(plain, dec);
                Assert.AreEqual(plain.Length, dec.Length);
            }
        }
Esempio n. 27
0
        public void StressTestSqlDateEncryption()
        {
            Random r     = new Random();
            int    times = 10000;

            for (int i = 0; i < times; i++)
            {
                int year  = r.Next(1900, 2020);
                int month = r.Next(1, 12);
                int date  = r.Next(1, 28);

                int hour   = r.Next(0, 23);
                int minute = r.Next(0, 59);
                int sec    = r.Next(0, 59);
                int ms     = r.Next(0, 999);
                var plain  = new DateTime(year, month, date, hour, minute, sec, ms);

                DateTime enc = FPEWrapper.EncryptSqlDateTime(key, tweak, plain);
                DateTime dec = FPEWrapper.DecryptSqlDateTime(key, tweak, enc);
                Console.WriteLine($"Src:{enc}, Dest:{dec}");
                Assert.AreEqual(plain, dec);
            }
        }
Esempio n. 28
0
 public void TestDecimalEncryptionMaxMinusOne()
 {
     FPEWrapper.EncryptDecimal(key, tweak, FPEWrapper.MaxAllowedDecimal - 0.00001M);
 }
Esempio n. 29
0
 public void TestDecimalEncryptionMinPlusOne()
 {
     FPEWrapper.EncryptDecimal(key, tweak, FPEWrapper.MinAllowedDecimal + 0.00001M);
 }
Esempio n. 30
0
 public void TestDecimalEncryptionMin()
 {
     FPEWrapper.EncryptDecimal(key, tweak, FPEWrapper.MinAllowedDecimal);
 }