April 21, 2015 07:36 by
Peter
In this tutorial, I will show you how to to encrypt/decrypt string in SQL Server. First step, you must write the following DB Script:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE Enc_Dec
@username varchar(20),
@password varchar(10)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @encrypt_val VARBINARY(200)
SELECT @encrypt_val = EncryptByPassPhrase('xxx', @password)
SELECT @encrypt_val
INSERT INTO reg_users (username,r_pwd)VALUES(@username ,CONVERT(VARCHAR(200), @encrypt_val, 1))
SELECT CONVERT(VARCHAR(200),DecryptByPassPhrase('xxx', @encrypt_val ))
END
GO
The output of the above code as shown in the following picture:
HostForLIFE.eu SQL Server 2014 with Free ASP.NET Hosting
Try our SQL Server 2014 with Free ASP.NET Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc. You will not be charged a cent for trying our service. Once your trial period is complete, you decide whether you'd like to continue.