- using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.IO;
-
using System.Security.Cryptography;
-
using System.Security;
-
using System.Runtime.InteropServices;
-
using System.Windows.Forms;
-
-
namespace cryptography
-
{
-
public partial class CRYPTROGRAPHY : Form
-
{
-
public CRYPTROGRAPHY()
-
{
-
InitializeComponent();
-
}
-
[System.Runtime.InteropServices.DllImport("Kernal32.DLL", EntryPoint = "RTLZeromemory")]
-
public static extern bool Zeromemory(IntPtr destination, int length);
-
-
public static string Generatekey()
-
{
-
DESCryptoServiceProvider descrpto = (DESCryptoServiceProvider)DESCryptoServiceProvider.Create();
-
return (ASCIIEncoding.ASCII.GetString(descrpto.Key));
-
}
-
-
public static void Encrypt(string inputfile, string outputfile, string skey)
-
{
-
FileStream fileinput = new FileStream(inputfile, FileMode.Open, FileAccess.Read);
-
FileStream fileoutput = new FileStream(outputfile, FileMode.Create , FileAccess.Write);
-
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
-
des.Key = ASCIIEncoding.ASCII.GetBytes(skey);
-
des.IV = ASCIIEncoding.ASCII.GetBytes(skey);
-
ICryptoTransform descrypt = des.CreateEncryptor();
-
CryptoStream cryptostream = new CryptoStream(fileoutput, descrypt, CryptoStreamMode.Write);
-
byte[] bytearray = new byte[fileinput.Length];
-
fileinput.Read(bytearray, 0, bytearray.Length);
-
cryptostream.Write(bytearray, 0, bytearray.Length);
-
fileoutput.Close();
-
}
-
public static void Decrypt(string inputfile, string outputfile, string skey)
-
{
-
try
-
{
-
-
FileStream fileoutput = new FileStream(outputfile, FileMode.Open, FileAccess.Write);
-
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
-
des.Key = ASCIIEncoding.ASCII.GetBytes(skey);
-
des.IV = ASCIIEncoding.ASCII.GetBytes(skey);
-
-
FileStream fileinput = new FileStream(inputfile, FileMode.Open, FileAccess.Read);
-
ICryptoTransform descrypt = des.CreateDecryptor();
-
CryptoStream cryptostreamdec = new CryptoStream(fileinput , descrypt, CryptoStreamMode.Read);
-
StreamWriter fsdec = new StreamWriter(outputfile);
-
fsdec.Write(new StreamReader(cryptostreamdec).ReadToEnd());//Here BADData error
-
fsdec.Flush();
-
fsdec.Close();
-
MessageBox.Show("Data Decrypted");
-
}
-
catch (IOException ex)
-
{
-
MessageBox.Show(ex.ToString());
-
}
-
-
catch (CryptographicException ex)
-
{
-
MessageBox.Show(ex.StackTrace);
-
}
-
}
-
//Browse button coding
-
private void btn_Browse_Click(object sender, EventArgs e)
-
{
-
openFileDialog1.Filter = "(.*txt)|*.txt";
-
if (openFileDialog1.ShowDialog() == DialogResult.OK)
-
{
-
txt_Filename.Text = openFileDialog1.FileName;
-
}
-
}
-
//Form Loading
-
private void CRYPTROGRAPHY_Load(object sender, EventArgs e)
-
{
-
toolStripStatusLabel1.Text = "Select File";
-
}
-
//Encrypt
-
private void btn_Enncrypt_Click(object sender, EventArgs e)
-
{
-
string mysecretkey = Generatekey();
-
txt_Secretkey.Text = mysecretkey;
-
Encrypt(txt_Filename.Text , txt_Save.Text , mysecretkey);//call encrypt method
-
toolStripStatusLabel1.Text = "Encrypting data";
-
-
}
-
-
//call decrypt method
-
private void btn_Decrypt_Click(object sender, EventArgs e)
-
{
-
string keyvalue = txt_Secretkey.Text;
-
Decrypt(txt_Filename.Text, txt_Save.Text, keyvalue);
-
}
-
}
-
}
4 2527 TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
You're going to have to give the volunteers here a bit more to go on that the entire code for your form.
Like *where* does the program break? On button_encrypt, or decrypt, or when you try to send it an entire file....
On what line does it break, and what is the exact error message you get?
how to rectify it plz modify this code
@jayabalan07
Dude, nobody here is going to do your homework for you.
Especially without some more to go on. Please refer to my earlier post that had QUESTIONS FOR YOU in it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike Chirico |
last post by:
With mysql-4.1.1-alpha, using any User Defined Function ( UDF) at the
query execution stage, on Linux 2.6, gave me the following error:
"ERROR 2013 (HY000): Lost connection to MySQL server...
|
by: Martin |
last post by:
Hi
Im trying to make a Client/Server where im going to encrypt the stream but i cant get it to work. I can recieve and send as long as im not trying to send/recieve encrypted. but when i am i cant...
|
by: Dave Bailey |
last post by:
I have developed a web app using DPAPI to encrypt a
connection string in the web.config file. The application
works perfectly on the development machine but when
deployed to the server when...
|
by: Microsoft news group |
last post by:
Every time when I try to create a new asp.net porject, I always get this
message:
The Web server reported the following error when attempting to create or
open the Web project located at the...
|
by: pebelund |
last post by:
Im having a problem I cant solve atm.
I got a webbserver, where Im doing a search, that will list some
information. The search goes to a seperate SQL 2000 server, to a stored
procedure that runs...
|
by: BigLuzer |
last post by:
hi
i am using the following setup:
- .net 1.1
- 2 load-balanced iis servers
- DPAPI machine store.
- C#
- i encrypted the connection string separately, one on each machine.
the error i get...
|
by: manmit.walia |
last post by:
Hello Everyone,
Long time ago, I posted a small problem I had about converting a VB6
program to C#. Well with the help with everyone I got it converted.
But I overlooked something and don't...
|
by: Elliot |
last post by:
When decrypt the xml, output "Unable to retrieve the decryption key."
Can anyone help me solve the problem?
I got the code from http://msdn.microsoft.com/en-us/library/ms229746.aspx
using...
|
by: Betikci Boris |
last post by:
I get bored last night and wrote a script that uses xor for encrypt-
decrypt, however it woks fine under linux 2.6.25, text and documents
are ok, but fails on compressed files *.jpg, *.pdf , etc ....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |