参数数据类型varchar对于EncryptByKey函数加密的参数3无效

时间:2013-03-28 01:50:02

标签: sql sql-server encryption

我目前正在进行评估并且在SQL加密方面遇到了一些麻烦,我需要在注册时加密其中三个列,这些列是varchar但是它们需要转换为varbinary以进行AES_256加密。我已经设置了密钥和证书,这只是我目前需要帮助的T SQL。

CREATE PROCEDURE dbo.Register
@Email nvarchar (60),
@Password varbinary (256),
@Fname varchar (24),
@Lname varchar (24),
@DoB date,
@HomePhoneNo nvarchar (20),
@MobileNo nvarchar (20),
@SecretQuestion1 varbinary (256),
@SecretQuestion2 varbinary (256)
AS
BEGIN
IF EXISTS (SELECT @Email FROM Customers.Customers)
DROP PROCEDURE dbo.Register
ROLLBACK

OPEN SYMMETRIC KEY Password_Key_DB
        DECRYPTION BY CERTIFICATE PasswordEncryption
        SET NOCOUNT ON
INSERT INTO Customers.Customers
VALUES 
(
@Email, 
ENCRYPTBYKEY(Key_GUID('Password_Key_DB'), @Password, CONVERT (varchar, @Password)),
@Fname, 
@Lname, 
@DoB,
@HomePhoneNo, 
@MobileNo,
ENCRYPTBYKEY(Key_GUID('Password_Key_DB'), @SecretQuestion1, CONVERT (varchar,                 @SecretQuestion1)),
ENCRYPTBYKEY(Key_GUID('Password_Key_DB'), @SecretQuestion2, CONVERT (varchar,     @SecretQuestion2))
)
END
GO

0 个答案:

没有答案