Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Example for encrypting data using XOR

Total Hit ( 1833)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Functions to encrypt data in columns are not available in SQL Server (except undocumented ones that are risky to use & not supported). Here is one that shows how to do this using XOR.

Click here to copy the following block
DECLARE @pwd varchar(30) , @encryptkey int , @encryptedpwd varchar(30) , @charpos smallint;
SELECT @pwd = 'shiloh2000' , @encryptedpwd = '' , @encryptkey = 24 , @charpos = 1
WHILE ( @charpos <= DATALENGTH( @pwd ) )
BEGIN
   SELECT @encryptedpwd = @encryptedpwd +
               CHAR( ASCII( SUBSTRING( @pwd , @charpos , 1) ) ^ @encryptkey ) ,
       @charpos = @charpos + 1;
END
SELECT @pwd AS OriginalPwd , @encryptedpwd AS EncryptedPwd
-- Sample Output:
/*
OriginalPwd          EncryptedPwd         
------------------------------ ------------------------------
shiloh2000           kpqtwp*(((
*/

go
/*
    To decrypt , the same logic can be applied with the values of
    original password & encrypted password reversed. This is the
    beauty of the XOR function. So you will use the encrypted
    password for @pwd & get the decrypted password as:

EncryptedPwd          OriginalPwd         
------------------------------ ------------------------------
kpqtwp*(((           shiloh2000          

*/


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.