5,702,067 members and growing! (15,953 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate

SQL Encrypt and decryption library (using rijndael)

By George Oakes

This library allows a user to use functions in SQL server to encrypt and decrypt text
VB, Windows, .NETSQL 2000, SQL 2005, VS2005, SQL Server, Visual Studio, DBA, Dev

Posted: 23 Aug 2006
Updated: 23 Aug 2006
Views: 20,544
Bookmarked: 14 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 2.21 Rating: 2.85 out of 5
2 votes, 33.3%
1
1 vote, 16.7%
2
0 votes, 0.0%
3
1 vote, 16.7%
4
2 votes, 33.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

I needed a way to be able to encrypt and decrypt text in SQL server and wanted an easy way to do this. I did not know C++ to build an extended procedure so using some code I was already using in other projects, I found a way to use a .NET library as a COM object that SQL could call into and it would handle the encryption and decryption. The Encryption algorythm is Rijndael, I used this because it is most commonly available on most platforms, as well as it is the new goverenment standard AES encryption method.

The following are the instuctions on how to build, install and run the sql scripts which are included in the ZIP code.

Installation Instructions:

 

1) build the library

To use this COM Object with your SQL server 2000 or 2005 compile this project with Visual Studio 2005, and the dll will be in the bin\release folder.

 

2) Create a strong named assembly

This project already has a strong named key but you may swap it out with your own. Buy building the project it is already strong named. You may remove this but you will be responsible for putting it where it belongs so the COM client can find it.

 

3) move the file so SQL can see the COM Object

Take the EncryptDecrypt.dll and copy that to your SQL servers binn folder. This is usually in the C:\Program Files\Microsoft SQL Server\MSSQL\Binn folder.

 

4) Generate a type library

Once you have copied the file you will need to register the component to make it visable to a COM client. You do this using the Regasm utility

 

Regasm /tlb:EncryptDecrypt binn\EncryptDecrypt.dll

 

5) Register the assembly in the GAC

In order for any COM clinet to see the .NET assembly, we need to register the assembly in the Global Assembly Cache, use the GACUTIl utility to register the assembly with the GAC

 

GACUTIL /i binn\EncryptDecrypt.dll

 

6) Install the functions to SQL

Open the EncryptDecryptFunctions.sql in your Query Analyzer select the database you wish to install the functions into, and execute the SQL script. This script will create 4 functions EncryptTextNoPWD, EncryptTextWPWD, DecryptTextNoPwd, and DecryptTextWPWD

 

The following are examples on how to use the functions in your SQL

 

--Encrypt text using the internal password

select dbo.EncryptStringnoPWD('test')

--Decrypt the encrypted text using the internal password

Select dbo.DecryptStringNoPWD('NzevW30d2I9egnLSz+PDvw==')

 

--Encrypt text using a user supplied password of ‘froggy’

select dbo.EncryptStringwPWD('test','froggy')

--Decrypt encrypted using a user supplied password of ‘froggy’

Select dbo.DecryptStringWPWD('eKO76BsvLSJMWK7kF6Mfpw==','froggy')

 

 

 

Good Luck and I hope this helps someone. If you find this software useful drop me an email and tell me about your experiences at OneSpecialDJ@yahoo.com

 

Peace

George

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

George Oakes


I have been developing software since 1995, and I enjoy it very much. My current position allows me to keep up with the latest technology, and it is refreshing.

I am married, and live with my wonderful wife, and our 2 lovely daughters, I have a son who is 18 and is out on his own learning about life.

I enjoy Hunting, Fishing, Shooting, and Auto racing. I live on the west coast of Florida and love every minute of it. The only thing I would change would be to move to the Keys, and swim and fish for a living Smile


Occupation: Web Developer
Location: United States United States

Other popular VB.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 14 of 14 (Total in Forum: 14) (Refresh)FirstPrevNext
NewsTwo other related encryption articles in CodeProject ...memberTony Selke8:02 27 Sep '07  
Generaltypes other then string?membernew bie23:03 21 Aug '07  
GeneralRe: types other then string?memberGeorge Oakes3:24 22 Aug '07  
GeneralRe: types other then string?membernew bie1:40 30 Aug '07  
GeneralRe: types other then string?memberGeorge Oakes4:51 30 Aug '07  
GeneralAlmost got it ....memberSteveCliff6:34 14 Jun '07  
GeneralRe: Almost got it ....memberSteveCliff6:51 14 Jun '07  
GeneralRe: Almost got it ....memberSteveCliff22:47 14 Jun '07  
GeneralWhat is the process to use this dll in asp ? [modified]memberRaghu Bhandari22:28 13 May '07  
GeneralRe: What is the process to use this dll in asp ?memberGeorge Oakes3:12 14 May '07  
GeneralGetting an error when tried in c#memberSagar VM20:27 19 Sep '06  
GeneralRe: Getting an error when tried in c#memberGeorge Oakes2:45 20 Sep '06  
GeneralGood Explanation !memberFarrukh_522:41 28 Aug '06  
GeneralRe: Good Explanation !memberGeorge Oakes2:24 29 Aug '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Aug 2006
Editor:
Copyright 2006 by George Oakes
Everything else Copyright © CodeProject, 1999-2008
Web09 | Advertise on the Code Project