String Encryption
String Encryption
String Encryption
String Encryption
String Encryption
String Encryption String Encryption String Encryption String Encryption String Encryption String Encryption String Encryption String Encryption
String Encryption String Encryption
String Encryption
Go Back  Xtreme Visual Basic Talk > > > > String Encryption


Reply
 
Thread Tools Display Modes
  #1  
Old 02-22-2006, 08:51 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default String Encryption


So I decided to play around with the encryption capabilities in the .NET framework this evening. The result is a little class library that will encrypt and decrypt a string. Optionally you can provide your own key and initialization vector, both in the format of a hex string. You don't have to provide them, but it would be much more secure if you don't use the defaults provided. You can use the library to generate new ones by calling the GenerateKey and GenerateIV respectively. Save the results in a secure place and use them when you want to encrypt or decrypt a string of text.

The way it works is this, you pass a string of text to the EncryptString function and it returns the encrypted result in the form of a hex string. You can then pass the hex string to the DecryptString function and get back the original string, provided the key and iv are set to the same values used during the encryption. Here is an example of using it:
Code:
Code:
Imports System Public Class Tester Public Shared Sub Main() Dim txt As String Dim helper As New StringEncryption.StringEncryption helper.Key = helper.GenerateKey helper.IV = helper.GenerateIV Console.WriteLine("Key: " & helper.Key) Console.WriteLine("IV: " & helper.IV) txt = "encryption is cool" Console.WriteLine("Before Encryption: " & txt) txt = helper.EncryptString(txt) Console.WriteLine("After Encryption: " & txt) txt = helper.DecryptString(txt) Console.WriteLine("After Decryption: " & txt) Console.ReadLine() End Sub End Class
This would be handy in situations where you have login and passwords stored in your applications, or app.config files, but don't want them to be easily deciphered. A password manager would be a good example of something where this would also be useful.

If you find any problems or have suggestions for improvement feel free to PM me.
Attached Files
File Type: zip Encryption.zip (10.9 KB, 208 views)
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy

Last edited by John; 02-22-2006 at 08:56 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
String Encryption
String Encryption
String Encryption String Encryption
String Encryption
String Encryption
String Encryption String Encryption String Encryption String Encryption String Encryption String Encryption String Encryption
String Encryption
String Encryption
 
String Encryption
String Encryption
 
-->