private static List <string> ReadFromFile()
        {
            List <string> entries = new List <string>();

            byte[] encryptedFile = null;

            // Read the whole file into a byte array
            lock (fileLock)
            {
                encryptedFile = File.ReadAllBytes(path);
            }

            if (encryptedFile.Any())
            {
                // Convert the secure key into a byte array
                byte[] privateKeyBytes = StringConverter.ToBytes(PrivateKey);

                // Decrypt the file using the key
                string decryptedFile = AESEncrypter.Decrypt(encryptedFile, privateKeyBytes);

                // Clear the key byte array for security reasons
                Array.Clear(privateKeyBytes, 0, privateKeyBytes.Length);

                // Split the decrypted file into strings representing serialized entries
                string[] serializedEntries = decryptedFile.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                // Add all serialized entries into the list
                entries.AddRange(serializedEntries);
            }

            return(entries);
        }
    // Loop principale:
    // Ogni secondo controlla se la postazione è occupata
    // Se lo è, mostra il messaggio "Postazione Occupata"
    // Se non lo è, genera il QR Code e lo mostra
    IEnumerator Loop()
    {
        bool generate = true;

        while (true)
        {
            yield return(StartCoroutine(IsLocationBusy(LocationID)));

            if (isBusy)
            {
                generate = true;
            }
            if (generate && !isBusy)
            {
                yield return(StartCoroutine(GetSessionToken(LocationID)));

                decryptedToken = AESEncrypter.Decrypt(lastToken, CypherKey);
                string    qrMessage = LocationID + "&" + decryptedToken;
                Texture2D tex2D     = CreateQRCode(qrMessage);
                QRCodeMaterial.SetTexture("_MainTex", tex2D);
                generate = false;
            }
            UpdateGraphics();
            yield return(new WaitForSeconds(1f));
        }
    }
        public void TestEncryptAndDecrypt()
        {
            string input = "Test";

            AESEncrypter encrypter = GetAESEncrypter();
            string       encrypted = encrypter.Encrypt(input);
            string       decrypted = encrypter.Decrypt(encrypted);

            Assert.AreEqual(input, decrypted);
        }
        private static void ReadFile(SecureString key)
        {
            using (WCFServiceClient client = new WCFServiceClient())
            {
                byte[] encryptedFile = client.ReadFile();

                if (encryptedFile != null)
                {
                    List <string> serializedEntries = new List <string>();

                    if (encryptedFile.Any())
                    {
                        string decryptedFile = AESEncrypter.Decrypt(encryptedFile, StringConverter.ToBytes(key));

                        serializedEntries.AddRange(decryptedFile.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries));
                    }

                    HashSet <EventEntry> entries = new HashSet <EventEntry>();
                    foreach (string serializedEntry in serializedEntries)
                    {
                        entries.Add(new EventEntry(serializedEntry));
                    }

                    if (!entries.Any())
                    {
                        Console.WriteLine("Entry list is empty");
                    }
                    else
                    {
                        foreach (var entry in entries)
                        {
                            Console.WriteLine(entry.ToString());
                        }
                    }
                }
            }
        }