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
target=”_blank” With XHTML 1.1
I received a question this morning from someone asking:
In XHTML 1.1 we cannot use attribute ‘target=blank’, so what is the solution?
The solution is to use regular links, but to make them open into a new window using JavaScript. To do this, we can add something to the links to flag them as being special, perhaps a class called new-window:
<a href="page.html" class="new-window">Page</a>
Then, use JavaScript to find all the links that have this class name and tell them to open in a new window:
window.onload = function() {
var links = document.getElementsByTagName('a');
for (var i=0;i < links.length;i++) {
if (links[i].className == 'new-window') {
links[i].onclick = function() {
window.open(this.href);
return false;
};
}
}
};
or using jQuery:
$(function(){
$('a.new-window').click(function(){
window.open(this.href);
return false;
});
});
If you have any other questions like this, feel free to ask me and I’ll be happy to answer them here.
Add comment April 16, 2009
Neoob :: Where start your objective ::
Neoob is a website design company focused on developing a professional image for businesses of all sizes whether just starting out on the Web or those seeking to improve their existing website.
With a team of creative web designers, developers and project managers, our firm is committed to service, collaboration, and communication throughout each step of the design process. Our team specializes in custom website design and hosting, database development, Flash animation, online branding, search engine placement and Internet marketing.
With Neoob, your success is how we measure our own!
Add comment April 16, 2009
PHP Cookies: How to Set Cookies & Get Cookies
Cookies don’t have to be an essential part of a website but can provide some of the “little things” that can set your website apart from the rest. Cookies are small tidbits of information that you save on the client’s computer so that you can access them next time they visit the website. Session ID’s are also usually held in cookies.
So what are the most popular uses of cookies? They are:
- To store username/password information so that the user doesn’t have to log in every time they visit the website (”remember me” sign ins).
- To simply remember the user’s name.
- To keep track of a user’s progress during a specified process.
- To remember a user’s theme.
Add comment April 15, 2009
Công ty Cổ phẩn Công nghệ và Truyền thông Tia Chớp Việt
Công ty Cổ phẩn Công nghệ và Truyền thông Tia Chớp Việt
11 Quách Văn Tuấn, phường 12, quận Tân Bình,
Thành phố Hồ Chí Minh
Điện thoại: (08) 62 938 186 – Fax: (08) 62 938 126
E-mail: lienhe@tiachopviet.com
Website: http://www.tiachopviet.com/
Công ty Cổ phần Công nghệ và Truyền thông Tia Chớp Việt là nhà cung cấp các dịch vụ:
* Thiết kế Website, phát triển các ứng dụng Web
* Phát triển phần mềm ứng dụng trong nhiều lĩnh vực
* Tư vấn giải pháp CNTT
* Lắp đặt bảo trì hệ thống mạng, máy tính
* Mua bán các linh kiện máy tính
* Thiết kế đồ họa
* In ấn
* Thương mại điện tử và quảng cáo trực tuyến.
(more…)
Add comment April 3, 2009