Exemple #1
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);
     }
 }
 internal void decryptFile(OpenFileDialog openFileDialog1, SaveFileDialog saveFileDialog)
 {
     if (fileManager.getFilePath(openFileDialog1, "Select file to decrypt", "Encrypted files (*.bin)|*.bin", "").ShowDialog() == DialogResult.OK)
     {
         String encryptedFilePath = openFileDialog1.FileName;
         String fileName          = fileManager.getOriginalNameAndFormat(encryptedFilePath);
         byte[] desc = rsa.decrypt(fileManager.loadDataFromFile(encryptedFilePath), key.getPrivateKey(), form1);
         String path = fileManager.getPathToSaveFile(saveFileDialog, null, null, fileName, "All files (*.*)|*.*");
         fileManager.createFileFromByte(desc, path);
         desc = null;
         GC.Collect();
     }
 }