Exemplo n.º 1
0
        private static void FindOtherKey(string keyFilePath)
        {
            var serializer = new SimpleModulusKeySerializer();

            serializer.Deserialize(keyFilePath, out uint[] modkey, out uint[] cryptKey, out uint[] xorKey);

            var generator     = new SimpleModulusKeyGenerator();
            var otherCryptKey = generator.FindOtherKey(modkey, cryptKey);
            var file          = new FileInfo(keyFilePath);
            var otherFileName = GetOtherFileName(file.Name);
            var otherFilePath = Path.Combine(file.DirectoryName, otherFileName);

            Console.WriteLine($"Calculation successful. To save the calculated key to file '{otherFilePath}' press any key");
            Console.ReadKey(true);
            serializer.Serialize(otherFilePath, modkey, otherCryptKey, xorKey);
            Console.WriteLine("Key saved");
        }
Exemplo n.º 2
0
        private static void FindOtherKey(string keyFilePath)
        {
            var serializer = new SimpleModulusKeySerializer();

            if (serializer.TryDeserialize(keyFilePath, out var modulusKey, out var cryptKey, out var xorKey))
            {
                Console.WriteLine($"Loaded Key:");
                Console.WriteLine($"   Modulus: {string.Join(", ", modulusKey.Select(k => k.ToString()))}");
                Console.WriteLine($"     Crypt: {string.Join(", ", cryptKey.Select(k => k.ToString()))}");
                Console.WriteLine($"       XOR: {string.Join(", ", xorKey.Select(k => k.ToString()))}");
                var generator     = new SimpleModulusKeyGenerator();
                var otherCryptKey = generator.FindOtherKey(modulusKey, cryptKey);
                var file          = new FileInfo(keyFilePath);
                var otherFileName = GetOtherFileName(file.Name);
                var otherFilePath = file.DirectoryName is null ? otherFileName : Path.Combine(file.DirectoryName, otherFileName);

                Console.WriteLine($"Calculated Crypt Key: {string.Join(", ", otherCryptKey.Select(k => k.ToString()))}");
                Console.WriteLine($"To save the calculated key file '{otherFilePath}' press any key");
                Console.ReadKey(true);
                serializer.Serialize(otherFilePath, modulusKey, otherCryptKey, xorKey);
                Console.WriteLine("Key saved");
            }
Exemplo n.º 3
0
        private static async Task GenerateNewKeyPair()
        {
            var generator = new SimpleModulusKeyGenerator();
            var result    = await generator.GenerateKeys().ConfigureAwait(false);

            Console.WriteLine("Generated key pair:");
            Console.WriteLine(result);
            Console.WriteLine(string.Empty);
            Console.WriteLine("If you want to save them, enter a number and hit enter. They will be saved as 'EncX.dat' and 'DecX.dat'.");
            if (int.TryParse(Console.ReadLine(), out int number))
            {
                var serializer = new SimpleModulusKeySerializer();
                serializer.Serialize($"Enc{number}.dat", result.ModulusKey, result.EncryptKey, result.XorKey);
                serializer.Serialize($"Dec{number}.dat", result.ModulusKey, result.DecryptKey, result.XorKey);
                Console.WriteLine("Keys saved, press any key to exit");
                Console.ReadKey(true);
            }
            else
            {
                Console.WriteLine("Not a valid number.");
            }
        }