通过网络创建非对称密钥

时间:2012-01-30 05:51:52

标签: sql-server sql-server-2008 assemblies public-key

我正在使用add an assembly尝试asymmetric key到SQL2008中的数据库。

我们使用十六进制字符串添加程序集(仅通过sql查询向程序集添加程序集)

USE [master] 
GO

IF NOT EXISTS (SELECT * from sys.asymmetric_keys where name = 'ManagedAsymmetricKey')
 BEGIN
  CREATE ASYMMETRIC KEY ManagedAsymmetricKey FROM FILE = 'C:\Managed.dll'
  CREATE LOGIN CLRLogin FROM ASYMMETRIC KEY ManagedAsymmetricKey
  GRANT UNSAFE ASSEMBLY TO CLRLogin
 END
GO

USE [$dbName]
GO
CREATE ASSEMBLY [Managed]
AUTHORIZATION [dbo]
FROM 0x4D5A....
WITH PERMISSION_SET = UNSAFE
GO

这将通过我们收到的网络在本地实例上运行; The certificate, asymmetric key, or private key file does not exist or has invalid format.

我可能错误地假设我应该首先添加密钥,我是否应该添加程序集然后执行CREATE ASYMMETRIC KEY ManagedAsymmetricKey FROM ASSEMBLY [workingDB].[dbo].[Managed]行?

2 个答案:

答案 0 :(得分:5)

您可以使用以下步骤使其正常工作:

  • 使用SAFE permission_set运行您的create assembly语句(即使程序集需要UNSAFE执行)
  • 从程序集
  • 创建非对称密钥
  • 放弃你的程序集
  • 从非对称密钥创建登录
  • 授予登录不安全程序集权限

    CREATE ASSEMBLY [Managed]
    AUTHORIZATION [dbo]
    FROM 0x4D5A....
    WITH PERMISSION_SET = SAFE
    
    CREATE ASYMMETRIC KEY ManagedAsymmetricKey FROM ASSEMBLY [Managed]
    
    DROP ASSEMBLY [Managed]
    
    CREATE LOGIN CLRLogin FROM ASYMMETRIC KEY ManagedAsymmetricKey
    
    GRANT UNSAFE ASSEMBLY TO CLRLogin
    

答案 1 :(得分:2)

FROM FILE =总是从SQL Server的角度出发。您可以将证书复制到数据库服务器上的本地驱动器。