コード例 #1
0
        public async Task <IHttpActionResult> GetMember(string memberID, string password)
        {
            PetterResultType <Member> petterResultType = new PetterResultType <Member>();
            List <Member>             members          = new List <Member>();
            Ciphers ciphers = new Ciphers();

            //var member = await db.Members.Where(p => p.MemberID == memberID.Trim().ToLower() & p.Password == password).SingleOrDefaultAsync();
            var member = await db.Members.Where(p => p.MemberID == memberID.Trim().ToLower()).SingleOrDefaultAsync();

            bool isPasswordMatch = ciphers.getPasswordMatch(member.Password, password);

            if (!isPasswordMatch)
            {
                member = null;
            }

            if (member == null)
            {
                await AddMemberAccess(memberID, AccessResult.Failure);

                return(NotFound());
            }

            await AddMemberAccess(memberID, AccessResult.Success);

            members.Add(member);
            petterResultType.IsSuccessful = true;
            petterResultType.JsonDataSet  = members;

            return(Ok(petterResultType));
        }
コード例 #2
0
        public async Task <IHttpActionResult> PutMember(string memberID, string password)
        {
            PetterResultType <Member> petterResultType = new PetterResultType <Member>();
            Ciphers       ciphers = new Ciphers();
            List <Member> members = new List <Member>();

            string hashcode = ciphers.getCryptPassword(password);

            var member = await db.Members.Where(p => p.MemberID == memberID).SingleOrDefaultAsync();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //db.Entry(member).State = EntityState.Modified;

            member.Password = hashcode;

            await db.SaveChangesAsync();

            members.Add(member);
            petterResultType.IsSuccessful = true;
            petterResultType.JsonDataSet  = members;

            return(Ok(petterResultType));
        }
コード例 #3
0
    //-------------------------------------------------
    private void EncryptStringTest(Ciphers.SymmetricAlgorithms Algorithm)
    {
        Console.Out.WriteLine("Running EncryptString Tests for {0}", Algorithm);
        string CipherText = "";
        string PlainText  = "";

        Console.Out.WriteLine(" * WeakPassword Test.");
        CipherText = Ciphers.EncryptString(Algorithm, Message, WeakPassword);
        PlainText  = Ciphers.DecryptString(Algorithm, CipherText, WeakPassword);
        Assert.AreNotEqual(Message, CipherText);
        Assert.AreEqual(Message, PlainText);

        Console.Out.WriteLine(" * StrongPassword Test.");
        CipherText = Ciphers.EncryptString(Algorithm, Message, StrongPassword);
        PlainText  = Ciphers.DecryptString(Algorithm, CipherText, StrongPassword);
        Assert.AreNotEqual(Message, CipherText);
        Assert.AreEqual(Message, PlainText);

        Console.Out.WriteLine(" * Passphrase Test.");
        CipherText = Ciphers.EncryptString(Algorithm, Message, Passphrase);
        PlainText  = Ciphers.DecryptString(Algorithm, CipherText, Passphrase);
        Assert.AreNotEqual(Message, CipherText);
        Assert.AreEqual(Message, PlainText);

        return;
    }
コード例 #4
0
    public void Test_002_HashString()
    {
        int i32a = Ciphers.HashString32(Message, WeakPassword);

        Console.Out.WriteLine("32-bit Hash with WeakPassword = {0}", i32a);
        int i32b = Ciphers.HashString32(Message, StrongPassword);

        Console.Out.WriteLine("32-bit Hash with StrongPassword = {0}", i32b);
        int i32c = Ciphers.HashString32(Message, Passphrase);

        Console.Out.WriteLine("32-bit Hash with Passphrase = {0}", i32c);
        Assert.AreNotEqual(i32a, i32b);
        Assert.AreNotEqual(i32a, i32c);
        Assert.AreNotEqual(i32b, i32c);

        long i64a = Ciphers.HashString64(Message, WeakPassword);

        Console.Out.WriteLine("64-bit Hash with WeakPassword = {0}", i64a);
        long i64b = Ciphers.HashString64(Message, StrongPassword);

        Console.Out.WriteLine("64-bit Hash with StrongPassword = {0}", i64b);
        long i64c = Ciphers.HashString64(Message, Passphrase);

        Console.Out.WriteLine("64-bit Hash with Passphrase = {0}", i64c);
        Assert.AreNotEqual(i64a, i64b);
        Assert.AreNotEqual(i64a, i64c);
        Assert.AreNotEqual(i64b, i64c);

        return;
    }
コード例 #5
0
 public static Cipher GetCipherByName(string cipherName)
 {
     if (Ciphers.TryGetValue(cipherName, out var cipher) == false)
     {
         throw new Exception($"encryption '{cipherName}' is not supported.\n(supported: {string.Join(", ", Ss.Ciphers.Keys)})");
     }
     return(cipher);
 }
コード例 #6
0
        private static void SortStates()
        {
            for (int i = Ciphers.Count - 1; i >= 0; i--)
            {
                if (DKAEndNodes.Contains(Ciphers[i]))
                {
                    Ciphers.Remove(Ciphers[i]);
                    Paths.Remove(Paths[i]);
                }
            }

            string        tempCipher;
            List <string> tempPath;

            for (int i = 0; i < Ciphers.Count; i++)
            {
                for (int j = i + 1; j < Ciphers.Count; j++)
                {
                    if (Convert.ToInt32(Ciphers[i].Split(',')[0]) > Convert.ToInt32(Ciphers[j].Split(',')[0]))
                    {
                        tempCipher = Ciphers[i];
                        Ciphers[i] = Ciphers[j];
                        Ciphers[j] = tempCipher;

                        tempPath = Paths[i];
                        Paths[i] = Paths[j];
                        Paths[j] = tempPath;
                    }
                }
            }

            for (int i = 0; i < DKAEndNodes.Count; i++)
            {
                for (int j = i + 1; j < DKAEndNodes.Count; j++)
                {
                    if (Convert.ToInt32(DKAEndNodes[i]) > Convert.ToInt32(DKAEndNodes[j]))
                    {
                        string tempNode = DKAEndNodes[i];
                        DKAEndNodes[i] = DKAEndNodes[j];
                        DKAEndNodes[j] = tempNode;
                    }
                }
            }

            DKAEndNodes.Add(DKAEndNodes[0]);
            DKAEndNodes.RemoveAt(0);

            Ciphers.AddRange(DKAEndNodes);
            for (int i = 0; i < DKAEndNodes.Count; i++)
            {
                Paths.Add(new List <string>());

                for (int k = 0; k < Labels.Length; k++)
                {
                    Paths[Paths.Count - 1].Add("$");
                }
            }
        }
コード例 #7
0
 private void CrossSetup()
 {
     Log("Cross Cipher :");
     for (int i = 0; i < 3; i++)
     {
         Log("Step {0} :".Form(i + 1));
         int col = RNG.Range(0, 5);
         int row = RNG.Range(0, 5);
         displayTexts[3, i + 1] += col + 1;
         displayTexts[3, i + 1] += row + 1;
         matrix = Ciphers.CrossCipher(matrix, col, row);
         Log("Display is {0}".Form(displayTexts[3, i + 1]));
         ShowMatrix();
     }
 }
コード例 #8
0
 private void RosaceSetup()
 {
     Log("Rosace Cipher :");
     for (int i = 0; i < 3; i++)
     {
         Log("Step {0} :".Form(i + 1));
         int  col         = RNG.Range(0, 5);
         int  row         = RNG.Range(0, 5);
         bool isClockwise = RNG.Range(0, 2) == 1;
         displayTexts[1, i + 1] += (char)(col + 'A');
         displayTexts[1, i + 1] += row + 1;
         displayTexts[1, i + 1] += isClockwise ? '>' : '<';
         matrix = Ciphers.RosaceCipher(matrix, row - 2, col - 2, isClockwise);
         Log("Display is {0}".Form(displayTexts[1, i + 1]));
         ShowMatrix();
     }
 }
コード例 #9
0
 private static void ChangeTransitions()
 {
     for (int i = 0; i < Paths.Count; i++)
     {
         for (int j = 0; j < Labels.Length; j++)
         {
             if (Paths[i][j] != "$" && Paths[i][j] != "")
             {
                 if (Paths[i][j].Contains("-"))
                 {
                     Paths[i][j] = Paths[i][j].Remove(Paths[i][j].IndexOf("-"));
                 }
                 Paths[i][j] += "-" + Suffixes[Ciphers.IndexOf(Paths[i][j])];
             }
         }
     }
 }
コード例 #10
0
 private void VitrailSetup()
 {
     Log("Vitrail Cipher :");
     for (int i = 0; i < 3; i++)
     {
         Log("Step {0} :".Form(i + 1));
         int colstart, colend;
         do
         {
             colstart = RNG.Range(0, 5);
             colend   = RNG.Range(0, 5);
         }while (colstart == colend);
         int overflow = RNG.Range(1, 6);
         displayTexts[2, i + 1] += colstart + 1;
         displayTexts[2, i + 1] += colend + 1;
         displayTexts[2, i + 1] += overflow;
         matrix = Ciphers.VitrailCipher(matrix, colstart, colend, overflow);
         Log("Display is {0}".Form(displayTexts[2, i + 1]));
         ShowMatrix();
     }
 }
コード例 #11
0
        private void FilterResults(string searchFilter, CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();

            if (string.IsNullOrWhiteSpace(searchFilter))
            {
                LoadSections(Ciphers, ct);
            }
            else
            {
                searchFilter = searchFilter.ToLower();
                var filteredCiphers = Ciphers
                                      .Where(s => s.Name.ToLower().Contains(searchFilter) ||
                                             (s.Subtitle?.ToLower().Contains(searchFilter) ?? false))
                                      .TakeWhile(s => !ct.IsCancellationRequested)
                                      .ToArray();

                ct.ThrowIfCancellationRequested();
                LoadSections(filteredCiphers, ct);
            }
        }
コード例 #12
0
ファイル: CiphersTest.cs プロジェクト: travisnielsen/FPE.Net
        public void testPrf()
        {
            Ciphers c = new Ciphers();

            Assert.IsNotNull(c);

            // null inputs
            try
            {
                byte[] K = null;
                byte[] P = { 1, 2, 1, 0, 0, 10, 10, 5, 0, 0, 0, 10, 0, 0, 0, 0 };
                byte[] Q = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)0xDD, (byte)0xD5 };
                c.prf(K, Common.concatenate(P, Q));
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOf <NullReferenceException>(e);
            }
            try
            {
                byte[] K = { (byte)0x2B, (byte)0x7E, (byte)0x15, (byte)0x16, (byte)0x28, (byte)0xAE, (byte)0xD2,
                             (byte)0xA6, (byte)0xAB, (byte)0xF7, (byte)0x15, (byte)0x88, (byte)0x09, (byte)0xCF,
                             (byte)0x4F, (byte)0x3C };
                c.prf(K, null);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOf <NullReferenceException>(e);
            }

            // wrong key type
            try
            {
                byte[] K = new byte[] { 0, 0, 0, 0, 0, 0, 0 };
                byte[] P = { 1, 2, 1, 0, 0, 10, 10, 5, 0, 0, 0, 10, 0, 0, 0, 0 };
                byte[] Q = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)0xDD, (byte)0xD5 };
                c.prf(K, Common.concatenate(P, Q));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // X is too short
            try
            {
                byte[] K = { (byte)0x2B, (byte)0x7E, (byte)0x15, (byte)0x16, (byte)0x28, (byte)0xAE, (byte)0xD2,
                             (byte)0xA6, (byte)0xAB, (byte)0xF7, (byte)0x15, (byte)0x88, (byte)0x09, (byte)0xCF,
                             (byte)0x4F, (byte)0x3C };
                byte[] X = { };
                c.prf(K, X);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // X is too long
            try
            {
                byte[] K = { (byte)0x2B, (byte)0x7E, (byte)0x15, (byte)0x16, (byte)0x28, (byte)0xAE, (byte)0xD2,
                             (byte)0xA6, (byte)0xAB, (byte)0xF7, (byte)0x15, (byte)0x88, (byte)0x09, (byte)0xCF,
                             (byte)0x4F, (byte)0x3C };
                byte[] X = new byte[Constants.MAXLEN + 1];
                c.prf(K, X);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // validation against sample data
            try
            {
                byte[] K = { (byte)0x2B, (byte)0x7E, (byte)0x15, (byte)0x16, (byte)0x28, (byte)0xAE, (byte)0xD2,
                             (byte)0xA6, (byte)0xAB, (byte)0xF7, (byte)0x15, (byte)0x88, (byte)0x09, (byte)0xCF,
                             (byte)0x4F, (byte)0x3C };
                byte[] P = { 1, 2, 1, 0, 0, 10, 10, 5, 0, 0, 0, 10, 0, 0, 0, 0 };
                byte[] Q = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)0xDD, (byte)0xD5 };
                byte[] R = { (byte)0xC3, (byte)0xB8, 41, (byte)0xA1, (byte)0xE8, 100, 43, 120, (byte)0xCC, 41,
                             (byte)0x94,        123, 59, (byte)0x93, (byte)0xDB, 99 };
                CollectionAssert.AreEquivalent(R, c.prf(K, Common.concatenate(P, Q)));
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
コード例 #13
0
ファイル: CiphersTest.cs プロジェクト: travisnielsen/FPE.Net
        public void testCiphers()
        {
            Ciphers c = new Ciphers();

            Assert.IsNotNull(c);
        }
コード例 #14
0
ファイル: CiphersTest.cs プロジェクト: travisnielsen/FPE.Net
        public void testCiph()
        {
            Ciphers c = new Ciphers();

            Assert.IsNotNull(c);

            // null inputs
            try
            {
                byte[] X = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
                c.ciph(null, X);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOf <NullReferenceException>(e);
            }
            try
            {
                byte[] K = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                c.ciph(K, null);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOf <NullReferenceException>(e);
            }

            // wrong key type
            try
            {
                byte[] K = { 0, 1, 2, 3, 4, 5, 6 };
                byte[] X = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
                c.ciph(K, X);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // X is too short
            try
            {
                byte[] K = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
                byte[] X = { };
                c.ciph(K, X);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // X is too long
            try
            {
                byte[] K = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
                byte[] X = new byte[Constants.MAXLEN + 1];
                c.ciph(K, X);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // NIST AES Core 128 sample 1
            try
            {
                byte[] K = { (byte)0x2B, (byte)0x7E, (byte)0x15, (byte)0x16, (byte)0x28, (byte)0xAE, (byte)0xD2,
                             (byte)0xA6, (byte)0xAB, (byte)0xF7, (byte)0x15, (byte)0x88, (byte)0x09, (byte)0xCF,
                             (byte)0x4F, (byte)0x3C };
                byte[] X = { (byte)0x6B, (byte)0xC1, (byte)0xBE, (byte)0xE2, (byte)0x2E, (byte)0x40, (byte)0x9F,
                             (byte)0x96, (byte)0xE9, (byte)0x3D, (byte)0x7E, (byte)0x11, (byte)0x73, (byte)0x93,
                             (byte)0x17, (byte)0x2A, (byte)0xAE, (byte)0x2D, (byte)0x8A, (byte)0x57, (byte)0x1E,
                             (byte)0x03, (byte)0xAC, (byte)0x9C, (byte)0x9E, (byte)0xB7, (byte)0x6F, (byte)0xAC,
                             (byte)0x45, (byte)0xAF, (byte)0x8E, (byte)0x51, (byte)0x30, (byte)0xC8, (byte)0x1C,
                             (byte)0x46, (byte)0xA3, (byte)0x5C, (byte)0xE4, (byte)0x11, (byte)0xE5, (byte)0xFB,
                             (byte)0xC1, (byte)0x19, (byte)0x1A, (byte)0x0A, (byte)0x52, (byte)0xEF, (byte)0xF6,
                             (byte)0x9F, (byte)0x24, (byte)0x45, (byte)0xDF, (byte)0x4F, (byte)0x9B, (byte)0x17,
                             (byte)0xAD, (byte)0x2B, (byte)0x41, (byte)0x7B, (byte)0xE6, (byte)0x6C, (byte)0x37,
                             (byte)0x10 };
                byte[] Y = { (byte)0x3A, (byte)0xD7, (byte)0x7B, (byte)0xB4, (byte)0x0D, (byte)0x7A, (byte)0x36,
                             (byte)0x60, (byte)0xA8, (byte)0x9E, (byte)0xCA, (byte)0xF3, (byte)0x24, (byte)0x66,
                             (byte)0xEF, (byte)0x97, (byte)0xF5, (byte)0xD3, (byte)0xD5, (byte)0x85, (byte)0x03,
                             (byte)0xB9, (byte)0x69, (byte)0x9D, (byte)0xE7, (byte)0x85, (byte)0x89, (byte)0x5A,
                             (byte)0x96, (byte)0xFD, (byte)0xBA, (byte)0xAF, (byte)0x43, (byte)0xB1, (byte)0xCD,
                             (byte)0x7F, (byte)0x59, (byte)0x8E, (byte)0xCE, (byte)0x23, (byte)0x88, (byte)0x1B,
                             (byte)0x00, (byte)0xE3, (byte)0xED, (byte)0x03, (byte)0x06, (byte)0x88, (byte)0x7B,
                             (byte)0x0C, (byte)0x78, (byte)0x5E, (byte)0x27, (byte)0xE8, (byte)0xAD, (byte)0x3F,
                             (byte)0x82, (byte)0x23, (byte)0x20, (byte)0x71, (byte)0x04, (byte)0x72, (byte)0x5D,
                             (byte)0xD4 };
                CollectionAssert.AreEquivalent(Y, c.ciph(K, X));
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
コード例 #15
0
        private static void DeleteRepeatedStates()
        {
            for (int i = 0; i < Paths.Count; i++)
            {
                for (int j = i + 1; j < Paths.Count; j++)
                {
                    bool areEquals = true;

                    for (int k = 0; k < Labels.Length; k++)
                    {
                        if (Paths[i][k] != Paths[j][k])
                        {
                            areEquals = false;
                            break;
                        }
                    }

                    if (areEquals && Paths[i][0] != "$" && !DKAEndNodes.Contains(Ciphers[j]) && !DKAEndNodes.Contains(Ciphers[i]))
                    {
                        Console.WriteLine("Найдены эквивалентные состояния: {0} и {1}\n", Ciphers[i], Ciphers[j]);

                        Paths[i].Clear();
                        Paths[i] = null;

                        for (int k = 0; k < Paths.Count; k++)
                        {
                            for (int f = 0; f < Labels.Length; f++)
                            {
                                if (Paths[k] == null)
                                {
                                    continue;
                                }

                                if (Paths[k][f].Contains(Ciphers[i]))
                                {
                                    Paths[k][f] = Paths[k][f].Replace(Ciphers[i], Ciphers[j]);
                                }
                            }
                        }

                        for (int k = 0; k < Ciphers.Count; k++)
                        {
                            if (k != i && Ciphers[k].Contains(Ciphers[i]))
                            {
                                Ciphers[k] = Ciphers[k].Replace(Ciphers[i], Ciphers[j]);
                            }
                        }

                        break;
                    }
                }
            }

            for (int i = 0; i < Paths.Count; i++)
            {
                if (Paths[i] == null)
                {
                    Paths.Remove(Paths[i]);
                    Ciphers.Remove(Ciphers[i]);
                }
            }
        }
コード例 #16
0
        public async Task <IHttpActionResult> PostMember()
        {
            PetterResultType <Member> petterResultType = new PetterResultType <Member>();
            Ciphers       ciphers = new Ciphers();
            List <Member> members = new List <Member>();
            Member        member  = new Member();

            if (Request.Content.IsMimeMultipartContent())
            {
                string folder = HostingEnvironment.MapPath(UploadPath.MemberPath);
                Utilities.CreateDirectory(folder);

                var provider = await Request.Content.ReadAsMultipartAsync();

                foreach (var content in provider.Contents)
                {
                    string fieldName = content.Headers.ContentDisposition.Name.Trim('"');
                    if (!string.IsNullOrEmpty(content.Headers.ContentDisposition.FileName))
                    {
                        var file = await content.ReadAsByteArrayAsync();

                        string fileName = Utilities.additionFileName(content.Headers.ContentDisposition.FileName.Trim('"'));

                        if (!FileExtension.MemberExtensions.Any(x => x.Equals(Path.GetExtension(fileName.ToLower()), StringComparison.OrdinalIgnoreCase)))
                        {
                            petterResultType.IsSuccessful = false;
                            petterResultType.JsonDataSet  = null;
                            petterResultType.ErrorMessage = ResultErrorMessage.FileTypeError;
                            return(Ok(petterResultType));
                        }

                        string fullPath = Path.Combine(folder, fileName);
                        File.WriteAllBytes(fullPath, file);
                        string thumbnamil = Path.GetFileNameWithoutExtension(fileName) + "_thumbnail" + Path.GetExtension(fileName);

                        Utilities.ResizeImage(fullPath, thumbnamil, FileSize.MemberWidth, FileSize.MemberHeight, ImageFormat.Png);
                        member.FileName = fileName;
                        member.FilePath = UploadPath.MemberPath.Replace("~", "");
                    }
                    else
                    {
                        string str = await content.ReadAsStringAsync();

                        string item = HttpUtility.UrlDecode(str);

                        #region switch case
                        switch (fieldName)
                        {
                        //case "MemberNo":
                        //    member.MemberNo = int.Parse(item);
                        //    break;
                        case "MemberID":
                            member.MemberID = item.ToLower();
                            break;

                        case "Password":
                            member.Password = ciphers.getCryptPassword(item);
                            break;

                        case "NickName":
                            member.NickName = item;
                            break;

                        case "Latitude":
                            member.Latitude = Convert.ToDouble(item);
                            break;

                        case "Longitude":
                            member.Longitude = Convert.ToDouble(item);
                            break;

                        default:
                            break;
                        }
                        #endregion switch case
                    }
                }

                string point = string.Format("POINT({0} {1})", member.Longitude, member.Latitude);
                member.Coordinate   = DbGeography.FromText(point);
                member.StateFlag    = StateFlags.Use;
                member.Route        = Route.App;
                member.DateCreated  = DateTime.Now;
                member.DateModified = DateTime.Now;
                db.Members.Add(member);
                int num = await this.db.SaveChangesAsync();

                members.Add(member);
                petterResultType.IsSuccessful = true;
                petterResultType.JsonDataSet  = members;
            }
            else
            {
                petterResultType.IsSuccessful = false;
                petterResultType.JsonDataSet  = null;
            }

            return(Ok(petterResultType));
        }