Click here to Skip to main content
15,917,540 members
Home / Discussions / C#
   

C#

 
GeneralRe: question on database query Pin
Jacky Yiu9-Dec-07 15:11
Jacky Yiu9-Dec-07 15:11 
Generalwhy update data is wrong.. Pin
angels7776-Dec-07 16:33
angels7776-Dec-07 16:33 
GeneralRe: why update data is wrong.. Pin
Jacky Yiu6-Dec-07 17:36
Jacky Yiu6-Dec-07 17:36 
GeneralRe: why update data is wrong.. Pin
angels7776-Dec-07 18:18
angels7776-Dec-07 18:18 
GeneralRe: why update data is wrong.. Pin
angels7776-Dec-07 18:55
angels7776-Dec-07 18:55 
GeneralRe: why update data is wrong.. Pin
Jacky Yiu6-Dec-07 22:07
Jacky Yiu6-Dec-07 22:07 
General[Message Deleted] Pin
rameshdontagani6-Dec-07 16:27
rameshdontagani6-Dec-07 16:27 
GeneralRe: simple selec tquery Pin
Michael Sync6-Dec-07 16:38
Michael Sync6-Dec-07 16:38 
GeneralC# Image Processing library Pin
peterchen6-Dec-07 15:38
peterchen6-Dec-07 15:38 
GeneralRe: C# Image Processing library Pin
Michael Sync6-Dec-07 16:33
Michael Sync6-Dec-07 16:33 
GeneralClose 'X' Pin
RussBus6-Dec-07 12:22
RussBus6-Dec-07 12:22 
GeneralRe: Close 'X' Pin
Justin Perez6-Dec-07 12:34
Justin Perez6-Dec-07 12:34 
GeneralRe: Close 'X' [modified] Pin
RussBus7-Dec-07 4:59
RussBus7-Dec-07 4:59 
GeneralUsing NPlot .NET component in Access VBA Pin
Thanks for all the fish6-Dec-07 11:59
Thanks for all the fish6-Dec-07 11:59 
GeneralRe: Using NPlot .NET component in Access VBA Pin
NassosReyzidis6-Dec-07 23:06
NassosReyzidis6-Dec-07 23:06 
QuestionUniqueness, authentication, licensing oh my Pin
askey6-Dec-07 10:46
askey6-Dec-07 10:46 
GeneralRe: Uniqueness, authentication, licensing oh my Pin
martin_hughes6-Dec-07 11:00
martin_hughes6-Dec-07 11:00 
GeneralRe: Uniqueness, authentication, licensing oh my Pin
DaveyM696-Dec-07 13:43
professionalDaveyM696-Dec-07 13:43 
GeneralRe: Uniqueness, authentication, licensing oh my Pin
askey6-Dec-07 17:05
askey6-Dec-07 17:05 
GeneralFile (XmlDocument) Encryption / Decryption improvements Pin
DaveyM696-Dec-07 8:21
professionalDaveyM696-Dec-07 8:21 
Hi,

After many hours of searching, I've managed to get this working using the code below - but I'm wondering if anyone has any suggestions on improving it? I'm sure this is not as efficient as it could be!

Also - how do I go about locking the target file during the read and write?

#region Encryption
    class RijndaelEncrypt
    {
        public static void Encrypt(XmlDocument ThisDocument, string FullPath)
        {
            //Save XML to memory stream
            MemoryStream ms = new MemoryStream();
            ThisDocument.Save(ms);
            //Convert memory stream to byte array
            byte[] xmlArray = ms.ToArray();
            //Encrypt
            RijndaelManaged Rij = new RijndaelManaged();
            Rij.Key = ASCIIEncoding.ASCII.GetBytes(Constants.Misc.MyKey); //MyKey is 16 character string
            Rij.IV = ASCIIEncoding.ASCII.GetBytes(Constants.Misc.MyKey);
            ICryptoTransform rijEncrypt = Rij.CreateEncryptor();
            byte[] encryptedData = rijEncrypt.TransformFinalBlock(xmlArray, 0, xmlArray.Length);
            //Create file stream and write encrypted data
            FileStream fsout = new FileStream(FullPath, FileMode.Create);
            fsout.Write(encryptedData, 0, encryptedData.Length);
            fsout.Close();
        }

        public static XmlDocument Decrypt(string FullPath)
        {
            //Create file stream and get file length
            FileStream fsin = new FileStream(FullPath, FileMode.Open, FileAccess.Read);
            FileInfo finfo = new FileInfo(FullPath);
            //Create binary reader and read from file stream
            BinaryReader br = new BinaryReader(fsin);
            //Decrypt
            byte[] encryptedData = br.ReadBytes((int)finfo.Length);
            RijndaelManaged Rij = new RijndaelManaged();
            Rij.Key = ASCIIEncoding.ASCII.GetBytes(Constants.Misc.MyKey);
            Rij.IV = ASCIIEncoding.ASCII.GetBytes(Constants.Misc.MyKey);
            ICryptoTransform rijDecrypt = Rij.CreateDecryptor();
            byte[] decryptedData = rijDecrypt.TransformFinalBlock(encryptedData, 0, encryptedData.Length);
            //Create XML document, fill with decrypted data and return the document
            XmlDocument ThisDocument = new XmlDocument();
            ThisDocument.LoadXml(Encoding.UTF8.GetString(decryptedData));
            return ThisDocument;
        }
    }
    #endregion

GeneralRe: File (XmlDocument) Encryption / Decryption improvements Pin
led mike6-Dec-07 8:57
led mike6-Dec-07 8:57 
GeneralRe: File (XmlDocument) Encryption / Decryption improvements Pin
DaveyM696-Dec-07 9:03
professionalDaveyM696-Dec-07 9:03 
GeneralRe: File (XmlDocument) Encryption / Decryption improvements Pin
Ennis Ray Lynch, Jr.6-Dec-07 9:12
Ennis Ray Lynch, Jr.6-Dec-07 9:12 
GeneralRe: File (XmlDocument) Encryption / Decryption improvements Pin
DaveyM696-Dec-07 9:23
professionalDaveyM696-Dec-07 9:23 
GeneralRe: File (XmlDocument) Encryption / Decryption improvements Pin
led mike6-Dec-07 9:49
led mike6-Dec-07 9:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.