Monday, June 14, 2010

Decrypt column data in SQL server

CREATE FUNCTION [dbo].[Decrypt] ( @EncryptedString NVARCHAR(4000) )

RETURNS VARCHAR(4000) WITH ENCRYPTION AS

BEGIN

DECLARE @vClearString VARCHAR(4000)

DECLARE @vIdx INT

DECLARE @vBaseIncrement INT

SET @vIdx = 1

SET @vBaseIncrement = 128

SET @vClearString = ''''

WHILE @vIdx <= LEN(@EncryptedString)

BEGIN

SET @vClearString = @vClearString +

CHAR(UNICODE(SUBSTRING(@EncryptedString, @vIdx, 1)) -

@vBaseIncrement - @vIdx + 1)

SET @vIdx = @vIdx + 1

END

RETURN @vClearString

END

To encrypt check following...

1 comment: