Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Security.Cryptography;

namespace CryptographicClasses
{
    class BigEncryption
    {
        public static void PubToXml()
        {
            var txt = string.Empty;
            using (var stream = File.OpenText("public_key.txt"))
            {
                txt = stream.ReadToEnd();
            }

            var xml = new XDocument(new XElement("Data", new XElement("info", txt)));
            xml.Save(Path.ChangeExtension("public_key.txt", ".xml"));
        }

        public static void PriToXml()
        {
            var txt = string.Empty;
            using (var stream = File.OpenText("private_key.txt"))
            {
                txt = stream.ReadToEnd();
            }

            var xml = new XDocument(new XElement("Data", new XElement("info", txt)));
            xml.Save(Path.ChangeExtension("private_key.txt", ".xml"));
        }

        public static string Encrypt()
        {
            try
            {
                PubToXml();
                RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                StreamReader readme = File.OpenText("public_key.xml");
                string rsaXml = readme.ReadToEnd();
                readme.Close();
                rsa.FromXmlString(rsaXml);
                Console.WriteLine("Enter text here");
                string message = Console.ReadLine();

                byte[] encrypted = rsa.Encrypt(System.Text.ASCIIEncoding.ASCII.GetBytes(message), false);

                FileStream steam = new FileStream("Lmessage.dat", FileMode.Create);
                steam.Write(encrypted, 0, encrypted.Length);
                steam.Close();
                
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            
            return "0";
        }

        public static string Decrypt()
        {
            PriToXml();
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            StreamReader readme = File.OpenText("private_key.xml");
            string rsaXml = readme.ReadToEnd();
            readme.Close();
            rsa.FromXmlString(rsaXml);
            string message = Console.ReadLine();

            byte[] decrypted = rsa.Decrypt(System.Text.ASCIIEncoding.ASCII.GetBytes(message), false);

            FileStream steam = new FileStream("Lmessage.dat", FileMode.Create);
            steam.Write(decrypted, 0, decrypted.Length);
            steam.Close();
            return "0";
        }
    }
}
Posted
Updated 26-May-14 7:06am
v4
Comments
[no name] 26-May-14 8:53am    
Just for the sake of argument, let us assume for a moment that the title of your posting is an actual question or description of some sort of a problem. The question for you is: what does this unformatted difficult to read code dump have to do with your problem?
segedy 26-May-14 9:02am    
I get the title error when I run the code.....I need help in fixing not a help in English
segedy 26-May-14 9:07am    
Really sorry about this...I posted the wrong code
[no name] 26-May-14 9:14am    
If you really expect help then you need to ask a question or describe a problem. Just dumping code here is not a question or a description of a problem. And posting code that is relevant to your problem would be a good idea too. Reading the FAQ for hints on how to ask a question would not be a bad idea either.
Kornfeld Eliyahu Peter 26-May-14 9:04am    
To be honest - nothing... :-)

1 solution

Access doesn't support stored procedures so you cannot use if exists() in your query.

I HIGHLY recommend dropping Access and using Sql Server Express instead.
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 26-May-14 9:12am    
A 5 just for 'dumping' Access...
segedy 26-May-14 12:53pm    
Please can you take a look at the code again......I posted the wrong one previously

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900