In this article is explained how to decrypt a symmetric key. For example:
SELECT SK.name, SK.symmetric_key_id, SK.key_length, SK.algorithm_desc,
KE.crypt_type_desc,
COALESCE(C.name,AK.name,PSK.name) AS protector_name,
KE.crypt_property AS encrypted_key,
COALESCE(DECRYPTBYCERT(C.certificate_id,KE.crypt_property),
DECRYPTBYASYMKEY(AK.asymmetric_key_id,KE.crypt_property)) AS decrypted_key
FROM sys.key_encryptions AS KE
JOIN sys.symmetric_keys AS SK
ON KE.key_id = SK.symmetric_key_id
LEFT JOIN sys.certificates AS C
ON KE.thumbprint = C.thumbprint
LEFT JOIN sys.asymmetric_keys AS AK
ON KE.thumbprint = AK.thumbprint
LEFT JOIN sys.symmetric_keys AS PSK
ON KE.thumbprint = CAST(PSK.key_guid AS VARBINARY(50));
It can be tested using the following query:
--
CREATE MASTER KEY ENCRYPTION
BY PASSWORD = 'smGK_MasterKeyPassword@';
--
CREATE CERTIFICATE [CERT_V001]
WITH SUBJECT = 'User for protecting SM symetric keys.'
--
CREATE SYMMETRIC KEY [SK_SecurityUsers_V001]
WITH ALGORITHM = AES_256 ENCRYPTION
BY CERTIFICATE [CERT_V001]
GO
DECLARE @Email NVARCHAR(128) = '[email protected]';
DECLARE @EmailEncrypted VARBINARY(256);
OPEN SYMMETRIC KEY [SK_SecurityUsers_V001] DECRYPTION
BY CERTIFICATE [CERT_V001];
SELECT @EmailEncrypted = ENCRYPTBYKEY(KEY_GUID('SK_SecurityUsers_V001'),@Email);
SELECT @EmailEncrypted;
CLOSE SYMMETRIC KEY [SK_SecurityUsers_V001];
OPEN SYMMETRIC KEY [SK_SecurityUsers_V001] DECRYPTION
BY CERTIFICATE [CERT_V001];
SELECT CONVERT(NVARCHAR(128), DECRYPTBYKEY(@EmailEncrypted));
CLOSE SYMMETRIC KEY [SK_SecurityUsers_V001];
--DROP SYMMETRIC KEY [SK_SecurityUsers_V001];
--DROP CERTIFICATE [CERT_V001];
--DROP MASTER KEY;
I am wondering, does this mean the data is not protected at all?
In the article is said, that:
However, for password-protected and symmetric-key-protected keys this sadly does not work.
I guess this means I need to use one of these types of encryption in order to be sure the data is protected?