Posts filed under '.Net'
Encrypting and decrypting data
I am seeing a lot of questions people are asking on how to do encryption/decryption. To help those people I have written a simple class encorporating several encryption/decryption functions:
-
byte[] Encrypt(byte[] clearData, byte[] Key, byte[] IV) – encrypts a byte array with a key and an IV and returns a byte array;
-
string Encrypt(string clearText, string Password) – encrypts a string with a password and returns a string;
-
byte[] Encrypt(byte[] clearData, string Password) - encrypts a byte array with a password and returns a byte array;
-
void Encrypt(string fileIn, string fileOut, string Password) – encrypts a file with a password and writes the encrypted bytes into another file.
For each of those there is also a corresponding Decrypt function. The Main method is a simple testing method that exercises some of those functions. The 2nd and the 3rd Encrypt functions call into the 1st function, so you will need to carry the 1st one around if you are using the 2nd or the 3rd. The last Encrypt function (the one that works with files) is standalone. I made it operate in a stream-like manner, without reading the whole file into memory, which makes it possible to encrypt/decrypt gigabytes of data without going out of memory space.
I am using Rijndael algorithm in this sample. The reason for this is that it is 100% implemented in managed code in our libraries, so it does not rely on CryptoAPI or any encryption packs and will work everywhere. If you need performance I would suggest replacing it with TripleDES (it is a one line change), and if you do, also do not forget to change the IV size to 8 bytes and the Key size to 16 bytes.
I have tried to document the code well, and I would like to encourage you to read through it and understand how it works, it should be pretty easy. You can also grab the whole thing, stick it into a .cs file and it should compile. If you run it you will see it make some test encryption/decryption roundtrip; you can also provide a file name as a parameter, and it will encrypt the file into a <name>.encrypted file and then decrypt it back into a <name>.decrypted.
Enjoy!
Add comment April 16, 2009
Doodable :: Best Business Solution, Web Design, Website Development, Graphic Design, Ecommerce Solutions, Outsourcing
Reliable Software Engineering from an Experienced TEAM of highly skilled programmers
About Doodable
Doodable was founded in the fall of 2009 and has quickly earned a reputation for superior engineering and client service.
We believe that engineering excellence is key, but hands-on service and transparent communication are also critical to any project’s success. Doodable delivers personalized service in an open communications environment to ensure that results match or exceed client expectations.
About Us
Our Mission
From The Doodable to Completion, we strive to constantly produce innovative solutions and services that add value to our customers.
Our Vision
To lead in the Invention and Development of advanced solutions for our Clients.
Our Philosophy
The cornerstone of any successful business is its ability to “listen & learn” its customer.
At The Doodable we are committed to growing with our clients by:
* Understanding their business challenges
* Aligning ourselves as a part of their team
* Developing solutions that improve business operations
* Assuring ROI
About Us
Focus
A disciplined focus on the unmet needs & expectations of customers, that plays a critical role in building solutions to give “Just What They Want”.
Collaborate
Use The Doodable expertise to benefit the clients through an open, collaborative approach. Our Industry Solutions ensure that we have specialist knowledge to address the particular challenges of different industries.
Quality
Our system is built on the premise that ensures a control over the processes by
* Applying clearly defined procedures
* Utilizing the best tools & skills for the job
* Ensuring frequent cross-functional audits
* Integrating a culture of continuous improvement
Consistent experience
Positive customer experiences are often the basis for translating customer engagements into long-term relationships.
Our philosophy is simple: Create sites that really work.
Borne of careful planning, each site we build is unique and built from the ground up. We use the latest tools in technology and design to meet and exceed our clients’ goals.
We invest our years of programming expertise and creative ability in each design we do. From Flash to database development, our web development team can create anything imaginable on the Web.
Our web site design expertise extends into following areas:
Web Design
Website Development
Graphic Design
Ecommerce Solutions
Outsourcing
Add comment April 3, 2009
Easier way to manage your ASP.NET Cache
Was recently told by a client of mine that the ASP.NET app I developed was WAY TOO SLOW! I had to agree; the site was pinging the database twice on every load of the home page. So I said, “Give me a week… I’ll make it work better”. I went home feeling bad… my app was slow and I really didn’t know where to begin. I had a lot of code that depended on pinging the database and I didn’t want to sift through it all. What I ended up doing was using the cache object.
I started to look at other open source projects and their approaches to caching. Than DotNetKicks’ cache manager caught my eye! I went off that idea and created my own way of implementing an object to interface with the cache object, making it more manageable.
The Cache manager I wrote has 3 methods (Grab, insert, clear), a constructor and 2 properties (CacheKey, CacheDuration). So here’s my code in VB and C#:
(more…)
Add comment January 23, 2008
Encrypt / Decrypt Section in Configuration File
Lets understand Encrypt and Decrypt particular section in web.config file with example of connectionstring encrypt in web.config file.
(more…)
Add comment January 18, 2008
URL Mapping in asp.net 2.0
URL Mapping is a mechanism by which you can change the displayed url in address bar.
Example:
Your asp.net application is developed from years, with convention frm as prefix to webform.
Add comment January 18, 2008