Ejemplo n.º 1
0
    bool checkListForL(ref SubConfig List1)
    {
        bool done = true;

        foreach (GameObject shape in List1.subconfiguration)
        {
            Magnet[] mag = shape.GetComponent <LShape>().GetComponentsInChildren <Magnet>();
            foreach (Magnet m in mag)
            {
                if (m.connection != null)
                {
                    foreach (GameObject L in subconfiguration)
                    {
                        if (m.connection.GetComponent <Magnet>().LShape == L)
                        {
                            if (!List1.subconfiguration.Contains(L))
                            {
                                List1.subconfiguration.Add(L);
                                return(false);
                            }
                        }
                    }
                }
            }
        }
        return(done);
    }
Ejemplo n.º 2
0
    public SubConfig Split()
    {
        bool      complete = false;
        SubConfig List1    = new SubConfig();
        SubConfig List2    = new SubConfig();

        List1.subconfiguration.Add(subconfiguration[0]);

        while (!complete)
        {
            complete = checkListForL(ref List1);
        }

        foreach (GameObject L in subconfiguration)
        {
            if (!List1.subconfiguration.Contains(L))
            {
                List2.subconfiguration.Add(L);
            }
        }

        subconfiguration = List1.subconfiguration;
        return(List2);

        //declare new list, put first l in it *DONE

        // check 1st L's joints for any other L that is in the OG list
        // if connected, put that other L in the new List
        // go to next connection to see if there are more, repeat untill no more connections in first L
        // move to next L in list (repeat)
        // once exhaused, put remaining L's in OG list to 2nd new List
    }
Ejemplo n.º 3
0
        private IronKeyResult GenerateKey(string password, SubConfig config)
        {
            CheckConfiguration(password, config);
            string salt = CreateSalt(config);

            byte[] iv = CreateIvBytes(config);
            return(GenerateKeyBasedOnSaltIvAndPassword(password, config, salt, iv));
        }
Ejemplo n.º 4
0
    public void addPiece(GameObject pieceToAdd)
    {
        numberOfPieces++;
        configuration.Add(pieceToAdd);
        SubConfig sc = new SubConfig();

        sc.subconfiguration.Add(pieceToAdd);
        subconfigs.Add(sc);
    }
Ejemplo n.º 5
0
        private IronDecryptResult Decrypt(string password, SubConfig config, byte[] toDecrypt)
        {
            var key = GenerateKey(password, config);

            using (var encryption = AlgorithmHelper.GetDecryption(config.Algorithm, key.Key, key.Iv))
            {
                return(DecryptWithCorrectDecryptionAlgorithm(toDecrypt, key, encryption));
            }
        }
Ejemplo n.º 6
0
        private IronEncryptResult Encrypt(string password, SubConfig config, string toEncrypt)
        {
            var key = GenerateKey(password, config);

            using (var encryption = AlgorithmHelper.GetEncryption(config.Algorithm, key.Key, key.Iv))
            {
                return(EncryptWithCorrectEncryption(toEncrypt, key, encryption));
            }
        }
Ejemplo n.º 7
0
        private static string CreateSalt(SubConfig config)
        {
            var salt = config.Salt;

            if (string.IsNullOrEmpty(salt))
            {
                salt = Guid.NewGuid().ToString("N");
            }

            return(salt);
        }
Ejemplo n.º 8
0
 private static void CheckConfiguration(string password, SubConfig config)
 {
     if (string.IsNullOrEmpty(password))
     {
         throw new IronMissingPasswordException("No password provided");
     }
     if (password.Length < AlgorithmHelper.GetNumberOfBits(config.Algorithm) / 8)
     {
         throw new IronConfigurationErrorException("Password buffer is too small");
     }
 }
Ejemplo n.º 9
0
        private static byte[] CreateIvBytes(SubConfig config)
        {
            var iv = config.Iv;

            if (iv == null)
            {
                iv = AlgorithmHelper.CreateIv(config.Algorithm);
            }

            return(iv);
        }
Ejemplo n.º 10
0
        private HmacResult HmacWithPassword(string password, SubConfig options, string toHmac)
        {
            var key     = GenerateKey(password, options);
            var hmac    = new HMACSHA256(key.Key);
            var hash    = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(toHmac));
            var hashB64 = Util.Base64UrlEncode(hash);

            return(new HmacResult()
            {
                Digest = hashB64,
                Salt = key.Salt
            });
        }
Ejemplo n.º 11
0
 public void Merge(SubConfig con1)
 {
     if (this != con1)
     {
         foreach (GameObject c in con1.subconfiguration)
         {
             if (!subconfiguration.Contains(c))
             {
                 subconfiguration.Add(c);
             }
         }
         GameManager.instance.config.subconfigs.Remove(con1);
     }
 }
Ejemplo n.º 12
0
 public IronConfig()
 {
     EncryptionConfig = new SubConfig()
     {
         Algorithm         = Algorithm.AES256cbc,
         SaltBits          = 256,
         Iterations        = 1,
         MinPasswordLength = 32
     };
     IntegrityConfig = new SubConfig()
     {
         Algorithm         = Algorithm.Sha256,
         SaltBits          = 256,
         Iterations        = 1,
         MinPasswordLength = 32
     };
 }
Ejemplo n.º 13
0
        private static IronKeyResult GenerateKeyBasedOnSaltIvAndPassword(string password, SubConfig config, string salt, byte[] iv)
        {
            var derivedBytes = new Rfc2898DeriveBytes(System.Text.Encoding.UTF8.GetBytes(password), System.Text.Encoding.UTF8.GetBytes(salt), config.Iterations);

            return(new IronKeyResult()
            {
                Key = derivedBytes.GetBytes(32),
                Salt = salt,
                Iv = iv
            });
        }