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); }
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 }
private IronKeyResult GenerateKey(string password, SubConfig config) { CheckConfiguration(password, config); string salt = CreateSalt(config); byte[] iv = CreateIvBytes(config); return(GenerateKeyBasedOnSaltIvAndPassword(password, config, salt, iv)); }
public void addPiece(GameObject pieceToAdd) { numberOfPieces++; configuration.Add(pieceToAdd); SubConfig sc = new SubConfig(); sc.subconfiguration.Add(pieceToAdd); subconfigs.Add(sc); }
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)); } }
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)); } }
private static string CreateSalt(SubConfig config) { var salt = config.Salt; if (string.IsNullOrEmpty(salt)) { salt = Guid.NewGuid().ToString("N"); } return(salt); }
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"); } }
private static byte[] CreateIvBytes(SubConfig config) { var iv = config.Iv; if (iv == null) { iv = AlgorithmHelper.CreateIv(config.Algorithm); } return(iv); }
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 }); }
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); } }
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 }; }
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 }); }