Encription in SQL Server | | here is a simple program is wrote for one of my projects to encript data in MS SQL Server (same version is written in oracle too).
CREATE FUNCTION EncryptPassword (
@Password as varchar(255)
)
RETURNS varchar(255)
AS
BEGIN
DECLARE @PasswordEncrypted as varchar(255)
DECLARE @PasswordLength as int
DECLARE @iPOS AS int
DECLARE @XOR AS int
--Ensure password IS NOT case-sensitive
SET @Password = lower(@Password)
--Only encrypt IF parameter IS NOT NULL
IF @Password IS NOT NULL
BEGIN
SET @PasswordLength = len(@Password)
-- CREATE the KEY using a combination the the lenth OF the password +
the pos of the first 'e' found in the PW.
-- (The 'e' IS the most commonly used letter IN the alphabet)
SET @XOR = @PasswordLength + charindex(@Password,'e')
SET @iPOS = 1
SET @PasswordEncrypted = ''
WHILE @iPOS <= @PasswordLength
BEGIN
SET @PasswordEncrypted = @PasswordEncrypted + char(Ascii(substring(@Password, @iPOS, 1)) ^ @XOR)
SET @iPOS = @iPOS + 1
END
END
--If @Password parameter IS NULL THEN do nothing
IF @Password IS NULL
BEGIN
SET @PasswordEncrypted = NULL
END
RETURN @PasswordEncrypted
END |