0% found this document useful (0 votes)
10 views

rsa11

شفرة rsall

Uploaded by

hjhswjbwjhwbn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

rsa11

شفرة rsall

Uploaded by

hjhswjbwjhwbn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
//using System.Runtime.InteropServices;
//using System.Runtime.CompilerServices;
namespace ConsoleApplication2GT {
class Program {
private static RSAParameters publickey;
private static RSAParameters privatekey;

public enum keysizes {


SIZE_512 = 512,
SIZE_1024 = 1024,
SIZE_2048 = 2048,
SIZE_952 = 952,
SIZE_1369 = 1369

};
static void Main(string[] args) {
Console.WriteLine("enter your massage");
string message =Console.ReadLine() ;
//string message = "My Name is Mohammed Al_Wsapi ";
generateKeys();
byte[] encrypted = Encrpt(Encoding.UTF8.GetBytes(message));
byte[] decrypted = Decrpt(encrypted);
Console.WriteLine("original\n\t" + message + "\n");
Console.WriteLine("Encrypted\n\t" +
BitConverter.ToString(encrypted).Replace("-","")+ "\n");
Console.WriteLine("Decrypted\n\t" + Encoding.UTF8.GetString(decrypted));
Console.ReadLine();
}
static void generateKeys()
{
using (var rsa = new RSACryptoServiceProvider(2048))
{
publickey = rsa.ExportParameters(true);

privatekey = rsa.ExportParameters(true);
}
}
static byte[] Encrpt(byte[] input)
{
byte[] encrypted;
using (var rsa = new RSACryptoServiceProvider(2048)) {

rsa.ImportParameters(publickey);
encrypted=rsa.Encrypt(input,true);
}
return encrypted;
}
static byte[] Decrpt(byte[] input)
{
byte[] decrypted;
using (var rsa = new RSACryptoServiceProvider(2048)) {
rsa.ImportParameters(privatekey);
decrypted = rsa.Decrypt(input, true);
}
return decrypted;
}

} }

You might also like