Beispiel #1
0
        static void Main(string[] args)
        {
            byte[]   file = File.ReadAllBytes(filename);
            MySha256 sha  = new MySha256();

            Client.PrintByteArray(sha.computeHash(file));

            SHA256 sha256 = SHA256.Create();

            Client.PrintByteArray(sha256.ComputeHash(file));
            do
            {
                Console.WriteLine("Для начала нажмите Enter");
            } while (Console.ReadKey().Key != ConsoleKey.Enter);
            try {
                Client client = new Client(1024, file);
                client.Process("127.0.0.1", 8888);
            } catch (SocketException exc) {
                Console.WriteLine($@"{exc.Message} Error code: {exc.ErrorCode}.");
            } catch (Exception ex) {
                Console.WriteLine(String.Format(ex.ToString()));
            } finally {
                Console.ReadLine();
            }
        }
Beispiel #2
0
        private void SendFileHash(PrivateKey pk)
        {
            MySha256 clientSha = new MySha256();
            var      hashValue = clientSha.computeHash(file);

            PrintByteArray(hashValue);

            var hash = ClientRsa.Encrypt(hashValue, pk.D, pk.N);

            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream    ms = new MemoryStream();

            Console.WriteLine(Commands.SendHash);
            SendCommand(Commands.SendHash);
            bf.Serialize(ms, hash);
            stream.Write(ms.ToArray(), 0, ms.ToArray().Length);
            MessageLog("Хеш отправлен");
        }
Beispiel #3
0
        private bool CheckHash(byte[] decryptedHash)
        {
            byte[] decryptedFile =
                File.ReadAllBytes(DecFilePath);

            MySha256 serverSha = new MySha256();
            var      hashValue = serverSha.computeHash(decryptedFile);

            Console.WriteLine("Хеш расшифрованного файла");
            PrintByteArray(hashValue);
            Console.WriteLine("Полученный хеш");
            PrintByteArray(decryptedHash);
            for (int i = 0; i < decryptedHash.Length; i++)
            {
                if (decryptedHash[i] != hashValue[i])
                {
                    return(false);
                }
            }

            return(true);
        }