public void encryptFile(OpenFileDialog openFileDialog1, SaveFileDialog saveFileDialog)
        {
            //OpenFileDialog openFileDialog = fileManager.getFilePath(openFileDialog1);
            if (fileManager.getFilePath(openFileDialog1, "Select file to encrypt", "All files (*.*)|*.*", "").ShowDialog() == DialogResult.OK)
            {
                String fileName = openFileDialog1.SafeFileName;
                String filePath = openFileDialog1.FileName;
                long[] encrypt;
                byte[] data = fileManager.getBytesFromFile(filePath);
                encrypt = rsa.encrypt(data, key.getPublicKey(), form1);

                String path = fileManager.getPathToSaveFile(saveFileDialog, null, null, "encrypted.bin", "Encrypted files (*.bin)|*.bin");
                if (path != null)
                {
                    fileManager.saveDataToFile(path, encrypt, fileName);
                    encrypt = null;
                    data    = null;
                    path    = null;
                    GC.Collect();
                }
                else
                {
                    encrypt = null;
                    data    = null;
                    path    = null;
                    GC.Collect();
                }
            }
        }
示例#2
0
 public UserKey saveKeysToFile(String path, RSA rsa, UserKey key)
 {
     key = rsa.generateKeyParis();
     if (path != null)
     {
         System.IO.File.WriteAllText(@path + "privateKey.txt", Convert.ToString(key.getPrivateKey()[0]) +
                                     "\n" + Convert.ToString(key.getPrivateKey()[1]) + "\n");
         System.IO.File.WriteAllText(@path + "publicKey.txt", Convert.ToString(key.getPublicKey()[0]) +
                                     "\n" + Convert.ToString(key.getPublicKey()[1]) + "\n");
         return(key);
     }
     else
     {
         return(key);
     }
 }