Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   Code Library (http://www.xtremevbtalk.com/code-library/)
-   -   String Encryption (http://www.xtremevbtalk.com/code-library/254776-string-encryption.html)

John 02-22-2006 07:51 PM

String Encryption
1 Attachment(s)
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:


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)

    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.

All times are GMT -6. The time now is 04:56 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.