.net, programming

VB.NET RC4 Encryption for database storage

I recently had to upgrade some Classic ASP code to .NET for some data encryption.  The routines use RC4 encryption and make the result database friendly.  The following class can easily be dropped into your project for use with little effort.  The sample code shows the encryption and decryption methods.  You just provide the message and the key for either instance.  From there you can drop it in your database or do whatever you want!

Sample Usage:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim plainText As String = “I’m exposed!”
Dim passkey As String = “keep me safe”

Dim safeText As String
safeText = Encryption.Encrypt(plainText, passkey)


Dim decrypted As String
decrypted = Encryption.Decrypt(safeText, passkey)


End Sub

You can view the entire class here.  If you’re looking for some quick and easy encryption this will do the trick.

Tagged , , ,

4 thoughts on “VB.NET RC4 Encryption for database storage

  1. I removed the Common namespace from the example. That’s how I had it in a project I was using. Re-run the code without the Common., or just see the post here with the updated example.

Leave a Reply

Your email address will not be published. Required fields are marked *