Aracılığıyla paylaş


DECRYPTBYKEYAUTOCERT (Transact-SQL)

Bir sertifika otomatik olarak şifresi çözülmüş olan bir simetrik anahtar kullanılarak şifresini çözer.

Topic link iconTransact-SQL sözdizimi kuralları

DecryptByKeyAutoCert ( cert_ID , cert_password 
        , { 'ciphertext' | @ciphertext }
    [ , { add_authenticator | @add_authenticator } 
    [ , { authenticator | @authenticator } ] ] )

Bağımsız değişkenler

  • cert_ID
    Is the ID of the certificate that is used to protect the symmetric key.cert_ID is int.

  • cert_password
    Özel anahtarın koruyan paroladır sertifika.Can be NULL if the private key is protected by the database master key.cert_password is varchar.

  • 'ciphertext'
    Is the data that was encrypted with the key.ciphertext is varbinary.

  • @ ciphertext
    Türünde bir değişken mi varbinary Ortak anahtar ile şifrelenmiş veriyi içerir.

  • add_authenticator
    Düz metin'ile birlikte bir doğrulayıcı şifrelenmiş olup olmadığını gösterir.Must be the same value that is passed to EncryptByKey when encrypting the data.Is 1 if an authenticator was used.add_authenticator is int.

  • @ add_authenticator
    Düz metin'ile birlikte bir doğrulayıcı şifrelenmiş olup olmadığını gösterir.Veri şifrelerken geçirilen EncryptByKey için aynı değeri olmalıdır.

  • authenticator
    Bir doğrulayıcı oluşturmak içinden veridir.Must match the value that was supplied to EncryptByKey.authenticator is sysname.

  • doğrulayıcı'nın
    Bir doğrulayıcı oluşturmak istediğiniz verileri içeren değişken belirtilir.EncryptByKey için sağlanan değerin eşleşmesi gerekir.

Dönüş Türleri

varbinary bir en büyük boyutu çok 8.000 bayt ile.

Remarks

DecryptByKeyAutoCert OPEN SIMETRIK ANAHTAR ve DecryptByKey birleştirir.Tek bir işlemle, bir simetrik anahtarın şifresini çözer ve cipher metin şifresini çözmek için bu anahtar kullanır.

İzinler

Gerektirir GÖRÜNÜM TANIMI simetrik anahtar ve izniDenetim izni sertifikadaki.

Örnekler

Aşağıdaki örnekte gösterildiği nasıl DecryptByKeyAutoCert bir şifre çözme yapan kodunu basitleştirmek için kullanılabilir. Bu kod, freshly yüklenmiş bir kopyasını çalıştırmalısınız AdventureWorks Veritabanı.

--Create the keys and certificate.
USE AdventureWorks;
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'mzkvdlk979438teag$$ds987yghn)(*&4fdg^';
OPEN MASTER KEY DECRYPTION BY PASSWORD = 'mzkvdlk979438teag$$ds987yghn)(*&4fdg^';
CREATE CERTIFICATE HumanResources037 
   WITH SUBJECT = 'Sammamish HR', 
   EXPIRY_DATE = '10/31/2009';
CREATE SYMMETRIC KEY SSN_Key_01 WITH ALGORITHM = DES
    ENCRYPTION BY CERTIFICATE HumanResources037;
GO
----Add a column of encrypted data.
ALTER TABLE HumanResources.Employee
    ADD EncryptedNationalIDNumber varbinary(128); 
OPEN SYMMETRIC KEY SSN_Key_01
   DECRYPTION BY CERTIFICATE HumanResources037 ;
UPDATE HumanResources.Employee
SET EncryptedNationalIDNumber
    = EncryptByKey(Key_GUID('SSN_Key_01'), NationalIDNumber);
GO
--
--Close the key used to encrypt the data.
CLOSE SYMMETRIC KEY SSN_Key_01;
--
--There are two ways to decrypt the stored data.
--
--OPTION ONE, using DecryptByKey()
--1. Open the symmetric key
--2. Decrypt the data
--3. Close the symmetric key
OPEN SYMMETRIC KEY SSN_Key_01
   DECRYPTION BY CERTIFICATE HumanResources037;
SELECT NationalIDNumber, EncryptedNationalIDNumber  
    AS 'Encrypted ID Number',
    CONVERT(nvarchar, DecryptByKey(EncryptedNationalIDNumber)) 
    AS 'Decrypted ID Number'
    FROM HumanResources.Employee;
CLOSE SYMMETRIC KEY SSN_Key_01;
--
--OPTION TWO, using DecryptByKeyAutoCert()
SELECT NationalIDNumber, EncryptedNationalIDNumber 
    AS 'Encrypted ID Number',
    CONVERT(nvarchar, DecryptByKeyAutoCert ( cert_ID('HumanResources037') , NULL ,EncryptedNationalIDNumber)) 
    AS 'Decrypted ID Number'
    FROM HumanResources.Employee;