aplikacja do szyfrowania i odszyfrowywania AES

0

Siemka!

W programowaniu jestem mega zielony, więc proszę o wyrozumiałość.
Mam pewien projekt z kryptografii dot. zaszyfrowania i odszyfrowywania pliku tekstowego i znalazłem taki kodzik:

using System;
using System.IO;
using System.Security.Cryptography;

namespace Aes_Example
{
    class AesExample
    {
        public static void Main()
        {
            string original = "Here is some data to encrypt!";

            // Create a new instance of the Aes
            // class.  This generates a new key and initialization
            // vector (IV).
            using (Aes myAes = Aes.Create())
            {

                // Encrypt the string to an array of bytes.
                byte[] encrypted = EncryptStringToBytes_Aes(original, myAes.Key, myAes.IV);

                // Decrypt the bytes to a string.
                string roundtrip = DecryptStringFromBytes_Aes(encrypted, myAes.Key, myAes.IV);

                //Display the original data and the decrypted data.
                Console.WriteLine("Original:   {0}", original);
                Console.WriteLine("Round Trip: {0}", roundtrip);
            }
        }
        static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
        {
            // Check arguments.
            if (plainText == null || plainText.Length <= 0)
                throw new ArgumentNullException("plainText");
            if (Key == null || Key.Length <= 0)
                throw new ArgumentNullException("Key");
            if (IV == null || IV.Length <= 0)
                throw new ArgumentNullException("IV");
            byte[] encrypted;

            // Create an Aes object
            // with the specified key and IV.
            using (Aes aesAlg = Aes.Create())
            {
                aesAlg.Key = Key;
                aesAlg.IV = IV;

                // Create an encryptor to perform the stream transform.
                ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

                // Create the streams used for encryption.
                using (MemoryStream msEncrypt = new MemoryStream())
                {
                    using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                    {
                        using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                        {
                            //Write all data to the stream.
                            swEncrypt.Write(plainText);
                        }
                        encrypted = msEncrypt.ToArray();
                    }
                }
            }

            // Return the encrypted bytes from the memory stream.
            return encrypted;
        }

        static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV)
        {
            // Check arguments.
            if (cipherText == null || cipherText.Length <= 0)
                throw new ArgumentNullException("cipherText");
            if (Key == null || Key.Length <= 0)
                throw new ArgumentNullException("Key");
            if (IV == null || IV.Length <= 0)
                throw new ArgumentNullException("IV");

            // Declare the string used to hold
            // the decrypted text.
            string plaintext = null;

            // Create an Aes object
            // with the specified key and IV.
            using (Aes aesAlg = Aes.Create())
            {
                aesAlg.Key = Key;
                aesAlg.IV = IV;

                // Create a decryptor to perform the stream transform.
                ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);

                // Create the streams used for decryption.
                using (MemoryStream msDecrypt = new MemoryStream(cipherText))
                {
                    using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                    {
                        using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                        {

                            // Read the decrypted bytes from the decrypting stream
                            // and place them in a string.
                            plaintext = srDecrypt.ReadToEnd();
                        }
                    }
                }
            }

            return plaintext;
        }
    }
}

Tylko jest tutaj na dany tekst, a nie plik tekstowy i tutaj jest moje pytanie - Gdzie trzeba zmienić w kodzie, aby szyfrowało plik tekstowy cały, a nie tylko jakiś tekst w kodzie?

Dziękuje za pomoc!

3
Homer2 napisał(a):

Siemka!

Gdzie trzeba zmienić w kodzie, aby szyfrowało plik tekstowy cały, a nie tylko jakiś tekst w kodzie?

screenshot-20210423094438.png

A niech mnie zbanują ale napiszę. To jest naprawdę wstyd. Cały Internet do dyspozycji, a Ty żeś nie włożył nawet minimalnej pracy własnej, by się dowiedzieć jak to zrobić, mimo, że pełno o tym w sieci.

Nie wiem: c#, how to encrypt file Wstyd! Co byś zrobił jakbyś miał takie zadanie i wyłącznie literaturę do dyspozycji? Bez sieci, bez Internetu?

Lenistwo, lenistwo i tumiwisizm - zrób to za mnie. Ot dzisiejsze społeczeństwo.

0

@Na zawsze nikt:

Na zawsze nikt napisał(a):
Homer2 napisał(a):

Siemka!

Gdzie trzeba zmienić w kodzie, aby szyfrowało plik tekstowy cały, a nie tylko jakiś tekst w kodzie?

screenshot-20210423094438.png

A niech mnie zbanują ale napiszę. To jest naprawdę wstyd. Cały Internet do dyspozycji, a Ty żeś nie włożył nawet minimalnej pracy własnej, by się dowiedzieć jak to zrobić, mimo, że pełno o tym w sieci.

Nie wiem: c#, how to encrypt file Wstyd! Co byś zrobił jakbyś miał takie zadanie i wyłącznie literaturę do dyspozycji? Bez sieci, bez Internetu?

Lenistwo, lenistwo i tumiwisizm - zrób to za mnie. Ot dzisiejsze społeczeństwo.

Dziękuje za pomoc :)
Szukałem, ale jeżeli za bardzo nie ogarniam nawet gdzie patrzeć, bo programowanie w ogóle mnie nie interesuje, oraz bardziej się spełniam w innych sektorach IT, to nie będę teraz siedział x godzin, aby ogarnąć coś co jest na studia ;) Zapytałem, wystarczyło zostawić screen i tyle, czasami nie rozumiem ludzi, którzy muszą dodać swoje 3 grosze.
Nie wiem co bym zrobił, jest internet, to korzystam jak pozostała część społeczeństwa ot to, takie czasy, trochę zrozumienia, nie każdy jest tak idealny jak Ty.
Temat do zamknięcia, rozwiązane.

0

nie będę teraz siedział x godzin, aby ogarnąć coś co jest na studia

Cóż, sam sobie wystawiasz świadectwo. Powodzenia na tych studiach życzę.

1 użytkowników online, w tym zalogowanych: 0, gości: 1