Exemplo n.º 1
0
        public static string GetVAsByteArray(InstructorValidationData aV, string instructorPassword)
        {
            try
            {
                //Serialize
                var ser = Framework_Project.Serialization.SerializationHelper.Serialize(aV);
                //Add special string at loca{0-2} to check for description in the future
                temp_ser = ser;
                ser      = "FCT" + ser;

                //compress before encryption is better to reduce size

                // var compressed = Framework_Project.Compression.CompressionHelper.Zip(ser);
                //Encrypt using student password
                string encrypted = AESGCM.SimpleEncryptWithPassword(ser, instructorPassword);

                int x;
                for (int i = 0; i < 100; i++)
                {
                    x = i;
                }

                return(encrypted);
            }
            catch (Exception ex)
            {
                throw new Exception("[Exception: Cannot Create GetVAsByteArray in Exam Helper ] [inner: " + ex.ToString());
            }
        }
Exemplo n.º 2
0
        private static void TestLibraries(bool testCompression = true, bool testEncryption = true)
        {
            var myOrgMsg   = "123456";
            var encryptedx = AESGCM.SimpleEncryptWithPassword(myOrgMsg, "123456");

            var decryptedx = AESGCM.SimpleDecryptWithPassword(encryptedx, "1234567");

            try
            {
                Parallel.For(0, 1000000, i =>
                {
                    var v          = new InstructorValidationData($"Std{i}", DateTime.Now, 10, 11);
                    var serialized = SerializationHelper.Serialize <InstructorValidationData>(v);
                    if (serialized == null)
                    {
                        throw new Exception("serialized==null");
                    }


                    string compressedString = Framework_Project.Compression.CompressionHelper.Zip(serialized);
                    if (compressedString == null)
                    {
                        throw new Exception("compressed==null");
                    }
                    //  string decompressed = Framework_Project.Compression.CompressionHelper.Unzip(compressedString);


                    string encrypted = AESGCM.SimpleEncryptWithPassword(compressedString, $"Keyyy{i}");
                    if (encrypted == null)
                    {
                        throw new Exception("encrypted==null");
                    }

                    string decrypted = AESGCM.SimpleDecryptWithPassword(encrypted, $"Keyyy{i}");
                    if (decrypted == null)
                    {
                        throw new Exception("decrypted==null");
                    }

                    if (decrypted != compressedString)
                    {
                        throw new Exception("decrypted!=compressedString");
                    }



                    if (!StructuralComparisons.StructuralEqualityComparer.Equals(decrypted, compressedString))
                    {
                        throw new Exception("decryptedBytes!=compressed");
                    }

                    string decompressed = Framework_Project.Compression.CompressionHelper.Unzip(decrypted);
                    if (decompressed == null)
                    {
                        throw new Exception("decompressed==null");
                    }
                    if (decompressed != serialized)
                    {
                        throw new Exception("decompressed != serialized");
                    }


                    var deserialized = SerializationHelper.Deserialize <InstructorValidationData>(serialized);
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }