New Posts New Posts RSS Feed: Using an Encrypted EntitySet
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Using an Encrypted EntitySet

 Post Reply Post Reply
Author
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Topic: Using an Encrypted EntitySet
    Posted: 08-Aug-2007 at 3:53pm
A recent Tech Tip called "Saving and Restoring the Cache" briefly covered one method of encrypting the cache.  Here's another, better performing, way to save and restore an encrypted cache which takes advantage of stream chaining.  This simple example uses DES (remember to use the same key and initialization vector for both encryption and decryption):
 
 
using System.Security.Cryptography;
 
string fileName = Application.UserAppDataPath + "\\MyLocalData.bin";
DES des = DES.Create();
DESCryptoServiceProvider desCSP = new DESCryptoServiceProvider();
 
To save to an encrypted file:
 
Stream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
CryptoStream cs = new CryptoStream(fs, desCSP.CreateEncryptor(des.Key, des.IV), CryptoStreamMode.Write);
 
mPersistenceManager.SaveEntitySet(cs, true);
 
And to restore an encrypted file:
 
Stream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
CryptoStream cs = new CryptoStream(fs, desCSP.CreateDecryptor(des.Key, des.IV), CryptoStreamMode.Read);
 
mPersistenceManager.RestoreEntitySet(cs, RestoreStrategy.Normal, true);

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down