mardi 5 mai 2015

Create Asymmetric key in SQL using a variable password (from stored procedure)

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

I want to create a new asymmetric key with new password each time, passed from the parameter of stored procedure. The issue is : "incorrect syntax near @mk. expecting STRING or TEXT_LEX." but it was impossible to convert from varchar to STRING using "cast" or "convert" I'm using SQL server 2014

Aucun commentaire:

Enregistrer un commentaire