コード例 #1
0
        private void btnSymmetricGenerate_Click(object sender, EventArgs e)
        {
            string key = Cryptography.Symmetric.CreateKey();

            WorkingDir.save(key, "tajni_kljuc.txt");
            textSymmetricKey.Text  = key;
            textSymmetricFile.Text = WorkingDir.directory + "\\" + "tajni_kljuc.txt";

            setSymmetricComponentVisibility(true);
        }
コード例 #2
0
        private void btnAsymmetricGenerate_Click(object sender, EventArgs e)
        {
            //generate keys
            Cursor.Current = Cursors.WaitCursor;
            Cryptography.Asymmetric.CreateKeys(out var publicKey, out var privateKey);
            richTextAsymmetricPrivateKey.Text = privateKey;
            richTextAsymmetricPublicKey.Text  = publicKey;
            Cursor.Current = Cursors.Default;

            //write to file
            WorkingDir.save(privateKey, "privatni_kljuc.txt");
            WorkingDir.save(publicKey, "javni_kljuc.txt");
            textAsymmetricPrivateFile.Text = WorkingDir.directory + "\\" + "privatni_kljuc.txt";
            textAsymmetricPublicFile.Text  = WorkingDir.directory + "\\" + "javni_kljuc.txt";

            setAsymmetricComponentVisibility(true);
        }
コード例 #3
0
 private void btnCalculateHash_Click(object sender, EventArgs e)
 {
     if (fileName != null)
     {
         string rawData      = File.ReadAllText(fileName);
         string readableHash = Cryptography.Hash.ConvertHashToString(Cryptography.Hash.Calculate(rawData));
         textHash.Text = readableHash;
         WorkingDir.save(readableHash, "hash.txt");
     }
     else
     {
         string            message = "Niste odabrali datoteku!";
         string            caption = "Input Error";
         MessageBoxButtons buttons = MessageBoxButtons.OK;
         MessageBox.Show(message, caption, buttons);
     }
 }
コード例 #4
0
 private void btnSignDigitally_Click(object sender, EventArgs e)
 {
     toggleComponents(false);
     if (originalFile != null && privateKey != null)
     {
         string fileContent = File.ReadAllText(originalFile);
         string pKey        = File.ReadAllText(privateKey);
         try
         {
             string digitalSignature = Convert.ToBase64String(Cryptography.DigitalSignature.Sign(fileContent, pKey));
             WorkingDir.save(digitalSignature, "digitalni_potpis.txt");
             labelSignatureStatus.Text      = "Datoteka uspješno potpisana!";
             labelSignatureStatus.ForeColor = Color.Green;
             textFilePath.Text = WorkingDir.directory + "\\" + "digitalni_potpis.txt";
             toggleComponents(true);
         }
         catch (Exception ex)
         {
             if (ex is CryptographicException || ex is System.FormatException)
             {
                 string            message = "Ključ ili datoteka nisu valjani!";
                 string            caption = "Signature Error";
                 MessageBoxButtons buttons = MessageBoxButtons.OK;
                 MessageBox.Show(message, caption, buttons);
             }
             else
             {
                 string            message = "Dogodila se greška, pokušajte ponovo!";
                 string            caption = "Unknown Error";
                 MessageBoxButtons buttons = MessageBoxButtons.OK;
                 MessageBox.Show(message, caption, buttons);
             }
         }
     }
     else
     {
         string            message = "Niste učitali sve potrebne podatke za potpisivanje!";
         string            caption = "Input Error";
         MessageBoxButtons buttons = MessageBoxButtons.OK;
         MessageBox.Show(message, caption, buttons);
     }
 }
コード例 #5
0
        private void btnSymmetricDecrypt_Click(object sender, EventArgs e)
        {
            richTextDecryptedFile.Text = "";
            if (encryptedFile != null && keyFile != null)
            {
                byte[] fileContent = Convert.FromBase64String(File.ReadAllText(encryptedFile));
                byte[] key         = Convert.FromBase64String(File.ReadAllText(keyFile));

                try
                {
                    string decryptedContent = Cryptography.Symmetric.Decrypt(fileContent, key);
                    WorkingDir.save(decryptedContent, "dekriptirani_tekst_simetricni.txt");
                    richTextDecryptedFile.Text = decryptedContent;
                    textDecryptedPath.Text     = WorkingDir.directory + "\\" + "dekriptirani_tekst_simetricni.txt";
                }
                catch (Exception ex)
                {
                    if (ex is CryptographicException || ex is System.FormatException)
                    {
                        string            message = "Ključ ili datoteka nisu valjani!";
                        string            caption = "Decrypt Error";
                        MessageBoxButtons buttons = MessageBoxButtons.OK;
                        MessageBox.Show(message, caption, buttons);
                    }
                    else
                    {
                        string            message = "Dogodila se greška, pokušajte ponovo!";
                        string            caption = "Unknown Error";
                        MessageBoxButtons buttons = MessageBoxButtons.OK;
                        MessageBox.Show(message, caption, buttons);
                    }
                }
            }
            else
            {
                string            message = "Niste učitali sve potrebne podatke za dekriptiranje!";
                string            caption = "Input Error";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                MessageBox.Show(message, caption, buttons);
            }
        }
コード例 #6
0
 private void btnAsymmetricEncrypt_Click(object sender, EventArgs e)
 {
     if (originalFile != null && publicKey != null)
     {
         string fileContent = File.ReadAllText(originalFile);
         string pKey        = File.ReadAllText(publicKey);
         try
         {
             byte[] encryptedContent = Cryptography.Asymmetric.Encrypt(fileContent, pKey);
             WorkingDir.save(Convert.ToBase64String(encryptedContent), "kriptirani_tekst_asimetricni.txt");
             richTextEncryptedFile.Text = Convert.ToBase64String(encryptedContent);
             textEncryptedPath.Text     = WorkingDir.directory + "\\" + "kriptirani_tekst_asimetricni.txt";
         }
         catch (Exception ex)
         {
             if (ex is CryptographicException || ex is System.FormatException)
             {
                 string            message = "Ključ ili datoteka nisu valjani!";
                 string            caption = "Encrypt Error";
                 MessageBoxButtons buttons = MessageBoxButtons.OK;
                 MessageBox.Show(message, caption, buttons);
             }
             else
             {
                 string            message = "Dogodila se greška, pokušajte ponovo!";
                 string            caption = "Unknown Error";
                 MessageBoxButtons buttons = MessageBoxButtons.OK;
                 MessageBox.Show(message, caption, buttons);
             }
         }
     }
     else
     {
         string            message = "Niste učitali sve potrebne podatke za kriptiranje!";
         string            caption = "Input Error";
         MessageBoxButtons buttons = MessageBoxButtons.OK;
         MessageBox.Show(message, caption, buttons);
     }
 }