create procedure SP_INS_PUBLIC_NHANVIEN
@manv varchar(20),
@hoten nvarchar(100),
@email varchar(20),
@luongcb varbinary ,
@tendn nvarchar(100),
@mk varchar
as
create asymmetric key mahoaluongi
with algorithm = RSA_512
encryption by password = @mk
insert into nhanvien values (@manv,@hoten,@email,ENCRYPTBYASYMKEY(mahoaluongi,@luongcb),@tendn,HASHBYTES('SHA1',@mk),@manv)
drop asymmetric key mahoaluongi
go
我想每次都使用新密码创建一个新的非对称密钥,从存储过程的参数传递。 我收到错误
@mk附近的语法不正确。期待STRING或TEXT_LEX。
但是使用cast
或convert
无法将varchar转换为STRING。
我正在使用SQL Server 2014
答案 0 :(得分:0)
我建议使用Exec Command作为以下查询:
create procedure SP_INS_PUBLIC_NHANVIEN
@manv varchar(20),
@hoten nvarchar(100),
@email varchar(20),
@luongcb varbinary ,
@tendn nvarchar(100),
@mk varchar
as
DECLARE @C NVARCHAR(MAX) =
'create asymmetric key mahoaluongi
with algorithm = RSA_512
encryption by password = '''+@mk+''''
EXEC(@C)
insert into nhanvien values (@manv,@hoten,@email,ENCRYPTBYASYMKEY(ASYMKEY_ID('mahoaluongi'),@luongcb),@tendn,HASHBYTES('SHA1',@mk),@manv)
Exec('drop asymmetric key mahoaluongi')
答案 1 :(得分:0)
ALTER PROCEDURE SP_INS_ENCRYPTED_KEY @name VARCHAR(20)
,@age INT
,@city VARCHAR(20)
,@mk VARCHAR(20)
AS
CREATE asymmetric KEY mahoaluongi
WITH algorithm = RSA_512 ENCRYPTION BY password = N'@mk'
INSERT INTO Emp@236186
VALUES (
@name
,@age
,ENCRYPTBYASYMKEY(AsymKey_ID('mahoaluongi'), @city)
)
DROP asymmetric KEY mahoaluongi
GO
答案 2 :(得分:0)
试试这个:
texts[i].length