Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
5
Answers
whats the problem in the running? rsa code
rooholah heydari
8y
450
1
Reply
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Security.Cryptography;
namespace
RSAEncryption
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
}
#region-----Encryptionand Decryption Function-----
static
public
byte
[] Encryption(
byte
[] Data, RSAParameters RSAKey,
bool
DoOAEPPadding)
{
try
{
byte
[] encryptedData;
using
(RSACryptoServiceProvider RSA =
new
RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
encryptedData = RSA.Encrypt(Data, DoOAEPPadding);
}
return
encryptedData;
}
catch
(CryptographicException e)
{
Console.WriteLine(e.Message);
return
null
;
}
}
static
public
byte
[] Decryption(
byte
[] Data, RSAParameters RSAKey,
bool
DoOAEPPadding)
{
try
{
byte
[] decryptedData;
using
(RSACryptoServiceProvider RSA =
new
RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
decryptedData = RSA.Decrypt(Data, DoOAEPPadding);
}
return
decryptedData;
}
catch
(CryptographicException e)
{
Console.WriteLine(e.ToString());
return
null
;
}
}
#endregion
#region--variables area
UnicodeEncoding ByteConverter =
new
UnicodeEncoding();
RSACryptoServiceProvider RSA =
new
RSACryptoServiceProvider();
byte
[] plaintext;
byte
[] encryptedtext;
#endregion
#region-- Function Implemantation
private
void
button1_Click(
object
sender, EventArgs e)
{
plaintext = ByteConverter.GetBytes(txtplain.Text);
encryptedtext = Encryption(plaintext, RSA.ExportParameters(
false
),
false
);
txtencrypt.Text = ByteConverter.GetString(encryptedtext);
}
private
void
button2_Click(
object
sender, EventArgs e)
{
byte
[] decryptedtex = Decryption(encryptedtext, RSA.ExportParameters(
true
),
false
);
txtdecrypt.Text = ByteConverter.GetString(decryptedtex);
}
#endregion
}
}
Error 1 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?) E:\asli\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs 18 33 WindowsFormsApplication1
Post
Reset
Cancel
Answers (
5
)
Next Recommended Forum
Help me to find error and correct the code
how to consume wsdl web service using gsoap in c++