Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 22nd, 2006, 01:12 AM
Authorized User
Join Date: Nov 2005
Location: hyderabad, andhra Pradesh, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jvraman
Default Encryption & Decryption

how to encrypt a data before storing it in the database and how to decrypt when retrieved.

Reply With Quote
  #2 (permalink)  
Old June 22nd, 2006, 02:48 AM
Friend of Wrox
Join Date: May 2006
Location: Helsingborg, , Sweden.
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts

Use this function for very simple encryption/decryption
CREATE FUNCTION dbo.fnSimpleEncDec
    @StringText VARCHAR(8000),
    @PasswordCharacter CHAR(1)

        @ReturnText VARCHAR(8000)

    SELECT @Index = DATALENGTH(@StringText),
        @ReturnText = ''

    WHILE @Index > 0
        SELECT @ReturnText = CHAR(ASCII(SUBSTRING(@StringText, @Index, 1)) ^ ASCII(@PasswordCharacter)) + @ReturnText,
            @Index = @Index - 1

    RETURN @ReturnText

To encrypt the fields, write

SET first_name = dbo.fnSimpleEncDec(first_name, '?'),
       last_name = dbo.fnSimpleEncDec(last_name, '*')

To decrypt the fields, write

SET first_name = dbo.fnSimpleEncDec(first_name, '?'),
       last_name = dbo.fnSimpleEncDec(last_name, '*')

You can use whatever character you like as password. There is one caveat or drawback! You can't use a password character that normally exist in the field, such as 'e'. If you do, SQL server truncates the string at the position where field contains same character as password character used.

For names, I would prefer using
SELECT dbo.fnSimpleEncDec(first_name, CHAR(31))
because then I will XOR 5 bits out of 8 for every character in the text to be encrypted or decrypted! And the text still looks somewhat normal.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Encryption/Decryption with rijndael ?!? vbmo Classic ASP Basics 3 November 17th, 2009 04:14 AM
Encryption/Decryption Problem param99 SQL Server 2000 4 December 14th, 2006 05:20 AM
Encryption and Decryption kvanchi General .NET 1 February 2nd, 2005 02:04 PM
Encryption and Decryption kvanchi General .NET 2 January 24th, 2005 02:52 PM
Encryption/Decryption using IUSR msrnivas General .NET 0 January 12th, 2005 12:35 AM

All times are GMT -4. The time now is 09:07 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.