无法插入加密数据?

时间:2018-10-19 20:04:41

标签: sql-server encryption sql-insert

我正在尝试将加密的数据插入到我的SQL Server表中。第一步,我创建了一个主密钥,一个证书和一个私钥:

CREATE MASTER KEY
ENCRYPTION BY PASSWORD = 'PASSWORD@123'
GO

CREATE CERTIFICATE ElipseCert
ENCRYPTION BY PASSWORD = 'SENHA@123'
WITH SUBJECT = 'Certificado Senha Usuario'
GO

CREATE SYMMETRIC KEY KeyElipse
WITH ALGORITHM = AES_256
ENCRYPTION BY CERTIFICATE ElipseCert 
GO

在我尝试插入数据之后:

OPEN SYMMETRIC KEY KeyElipse
DECRYPTION BY CERTIFICATE ElipseCert

DECLARE @GUID UNIQUEIDENTIFIER = (SELECT KEY_GUID('KeyElipse'))
INSERT INTO Usuario VALUES ('FONSECA', ENCRYPTBYKEY(@GUID, 'Abcd1234'))
GO

SELECT * FROM Usuario

CLOSE SYMMETRIC KEY KeyElipse

但是当我执行代码时,我会返回:

  

证书具有一个私钥,该私钥受用户定义的密码保护。需要提供该密码才能启用私钥。

怎么了?

非常感谢!

1 个答案:

答案 0 :(得分:1)

  

证书具有一个私钥,该私钥受用户定义的密码保护。需要提供该密码才能启用私钥

因此请提供密码,替换此代码

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>

<p style="cursor:default;border:2px solid black;width:60px;padding:5px;">Click me</p>
<span><span>

</body>
</html>

与此一起

var partition = function (arr, low, high) {
    var x = arr[high]
    var i = low - 1
    for (var j = low; j <= high - 1; j++) {
        if (arr[j] <= x) {
            i++
            var temp = arr[i]
            arr[i] = arr[j]
            arr[j] = temp
        }
    }
    var temp = arr[i + 1]
    arr[i + 1] = arr[high]
    arr[high] = temp
    return i + 1 
}

var quickSort = function (arr, low, high) {
    if (low < high) {
        index = partition(arr,low,high)
        if (low < index-1) quickSort(arr,low,index-1)
        if (index+1 < high) quickSort(arr,index+1,high)
    }
}

var list2 = [1000,13,12,1001,82,1,2,4,3,0]

console.log(quickSort(list2,0,list2.length))