Skip to content

Commit ac0563f

Browse files
authored
Merge pull request #5530 from MicrosoftDocs/FromPublicRepo
Confirm merge from FromPublicRepo to master to sync with https://github.com/MicrosoftDocs/sql-docs (branch live)
2 parents 8425e85 + 8ccf675 commit ac0563f

3 files changed

Lines changed: 31 additions & 29 deletions

File tree

docs/t-sql/functions/certencoded-transact-sql.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ms.workload: "Inactive"
2929
# CERTENCODED (Transact-SQL)
3030
[!INCLUDE[tsql-appliesto-ss2012-asdb-xxxx-xxx-md](../../includes/tsql-appliesto-ss2012-asdb-xxxx-xxx-md.md)]
3131

32-
Returns the public portion of a certificate in binary format. This function takes a certificate ID and returns the encoded certificate. The binary result can be passed to **CREATE CERTIFICATE … WITH BINARY** to create a new certificate.
32+
This function returns the public portion of a certificate in binary format. This function takes a certificate ID as an argument, and returns the encoded certificate. To create a new certificate, pass the binary result to **CREATE CERTIFICATE … WITH BINARY**.
3333

3434
## Syntax
3535

@@ -39,39 +39,39 @@ CERTENCODED ( cert_id )
3939

4040
## Arguments
4141
*cert_id*
42-
Is the **certificate_id** of the certificate. This is available from sys.certificates or by using the [CERT_ID (Transact-SQL)](../../t-sql/functions/cert-id-transact-sql.md) function. *cert_id* is type **int**
42+
The **certificate_id** of the certificate. Find this value in sys.certificates; the [CERT_ID (Transact-SQL)](../../t-sql/functions/cert-id-transact-sql.md) function will return it as well. *cert_id* has data type **int**.
4343

4444
## Return types
4545
**varbinary**
4646

4747
## Remarks
48-
**CERTENCODED** and **CERTPRIVATEKEY** are used together to return different portions of a certificate in binary form.
48+
Use **CERTENCODED** and **CERTPRIVATEKEY** together to return, in binary form, different portions of a certificate.
4949

5050
## Permissions
51-
**CERTENCODED** is available to public.
51+
**CERTENCODED** is publicly available.
5252

5353
## Examples
5454

5555
### Simple Example
56-
The following example creates a certificate named `Shipping04` and then uses the **CERTENCODED** function to return the binary encoding of the certificate.
56+
This example creates a certificate named `Shipping04`, and then uses the **CERTENCODED** function to return the binary encoding of the certificate. This example sets the certificate expiry date to October 31, 2040.
5757

5858
```sql
59-
CREATE DATABASE TEST1;
60-
GO
61-
USE TEST1
62-
CREATE CERTIFICATE Shipping04
63-
ENCRYPTION BY PASSWORD = 'pGFD4bb925DGvbd2439587y'
64-
WITH SUBJECT = 'Sammamish Shipping Records',
65-
EXPIRY_DATE = '20161031';
66-
GO
67-
SELECT CERTENCODED(CERT_ID('Shipping04'));
59+
CREATE DATABASE TEST1;
60+
GO
61+
USE TEST1
62+
CREATE CERTIFICATE Shipping04
63+
ENCRYPTION BY PASSWORD = 'pGFD4bb925DGvbd2439587y'
64+
WITH SUBJECT = 'Sammamish Shipping Records',
65+
EXPIRY_DATE = '20401031';
66+
GO
67+
SELECT CERTENCODED(CERT_ID('Shipping04'));
6868

6969
```
7070

7171
### B. Copying a Certificate to Another Database
72-
The following more complicated example, creates two databases, `SOURCE_DB` and `TARGET_DB`. The goal is to create a certificate in the `SOURCE_DB`, and then copy the certificate to the `TARGET_DB`, and then demonstrate that data encrypted in `SOURCE_DB` can be decrypted in `TARGET_DB` using the copy of the certificate.
72+
The more complex example creates two databases, `SOURCE_DB` and `TARGET_DB`. Then, create a certificate in `SOURCE_DB`, and then copy the certificate to the `TARGET_DB`. Finally, demonstrate that data encrypted in `SOURCE_DB` can be decrypted in `TARGET_DB` using the copy of the certificate.
7373

74-
To create the example environment, create the `SOURCE_DB` and `TARGET_DB` databases, and a master key in each. Then create a certificate in `SOURCE_DB`.
74+
To create the example environment, create the `SOURCE_DB` and `TARGET_DB` databases, and a master key in each database. Then, create a certificate in `SOURCE_DB`.
7575

7676
```sql
7777
USE master;
@@ -96,7 +96,7 @@ CREATE CERTIFICATE SOURCE_CERT WITH SUBJECT = 'SOURCE_CERTIFICATE';
9696
GO
9797
```
9898

99-
Now extract the binary description of the certificate.
99+
Next, extract the binary description of the certificate.
100100

101101
```sql
102102
DECLARE @CERTENC VARBINARY(MAX);
@@ -109,7 +109,7 @@ SELECT @CERTPVK AS EncryptedBinaryCertificate;
109109
GO
110110
```
111111

112-
Create the duplicate certificate in the `TARGET_DB` database. You must modify the following code, inserting the two binary values returned in the previous step.
112+
Then, create the duplicate certificate in the `TARGET_DB` database. Modify the following code for this to work, inserting the two binary values - @CERTENC and @CERTPVK - returned in the previous step. Don't surround these values with quotes.
113113

114114
```sql
115115
-- Create the duplicate certificate in the TARGET_DB database
@@ -128,7 +128,7 @@ UNION
128128
SELECT * FROM TARGET_DB.sys.certificates;
129129
```
130130

131-
The following code executed as a single batch demonstrates that data encrypted in `SOURCE_DB` can be decrypted in `TARGET_DB`.
131+
This code, executed as a single batch, demonstrates that `TARGET_DB` can decrypt data originally encrypted in `SOURCE_DB`.
132132

133133
```sql
134134
USE SOURCE_DB;

docs/t-sql/functions/certprivatekey-transact-sql.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ ms.workload: "Inactive"
2929
# CERTPRIVATEKEY (Transact-SQL)
3030
[!INCLUDE[tsql-appliesto-ss2012-asdb-xxxx-xxx-md](../../includes/tsql-appliesto-ss2012-asdb-xxxx-xxx-md.md)]
3131

32-
Returns the private key of a certificate in binary format. This function takes three arguments.
32+
This function returns the private key of a certificate in binary format. This function takes three arguments.
3333
- A certificate ID.
34-
- An encryption password which is used to encrypt the private key bits when they are returned by the function, so that the keys are not exposed clear text to users.
35-
- A decryption password which is optional. If a decryption password is specified, then it is used to decrypt the private key of the certificate otherwise database master key is used.
34+
- An encryption password, used to encrypt the private key bits returned by the function. This approach does not expose the keys as clear text text to users.
35+
- An optional decryption password. A specified decryption password is used to decrypt the private key of the certificate. Otherwise, the database master key is used.
3636

37-
Only users that have access to certificate’s private key will be able to use this function. This function returns the private key in PVK format.
37+
Only users with access to the certificate private key can use this function. This function returns the private key in PVK format.
3838

3939
## Syntax
4040

@@ -49,7 +49,7 @@ CERTPRIVATEKEY
4949

5050
## Arguments
5151
*certificate_ID*
52-
Is the **certificate_id** of the certificate. This is available from sys.certificates or by using the [CERT_ID (Transact-SQL)](../../t-sql/functions/cert-id-transact-sql.md) function. *cert_id* is type **int**
52+
The **certificate_id** of the certificate. Obtain this value from sys.certificates or from the [CERT_ID (Transact-SQL)](../../t-sql/functions/cert-id-transact-sql.md) function. *cert_id* has data type **int**.
5353

5454
*encryption_password*
5555
The password used to encrypt the returned binary value.
@@ -61,10 +61,10 @@ The password used to decrypt the returned binary value.
6161
**varbinary**
6262

6363
## Remarks
64-
**CERTENCODED** and **CERTPRIVATEKEY** are used together to return different portions of a certificate in binary form.
64+
Use **CERTENCODED** and **CERTPRIVATEKEY** together to return different portions of a certificate, in binary form.
6565

6666
## Permissions
67-
**CERTPRIVATEKEY** is available to public.
67+
**CERTPRIVATEKEY** is publicly available.
6868

6969
## Examples
7070

@@ -76,12 +76,12 @@ CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Use 5tr0ng P^55Words'
7676
GO
7777
CREATE CERTIFICATE Shipping04
7878
WITH SUBJECT = 'Sammamish Shipping Records',
79-
EXPIRY_DATE = '20141031';
79+
EXPIRY_DATE = '20401031';
8080
GO
8181
SELECT CERTPRIVATEKEY(CERT_ID('Shipping04'), 'jklalkaa/; uia3dd');
8282
```
8383

84-
For a more complex example that uses **CERTPRIVATEKEY** and **CERTENCODED** to copy a certificate to another database, see example B in the topic [CERTENCODED (Transact-SQL)](../../t-sql/functions/certencoded-transact-sql.md).
84+
See [CERTENCODED (Transact-SQL)](../../t-sql/functions/certencoded-transact-sql.md), Example B, for a more complex example that uses **CERTPRIVATEKEY** and **CERTENCODED** to copy a certificate to another database.
8585

8686
## See also
8787
[Security Functions (Transact-SQL)](../../t-sql/functions/security-functions-transact-sql.md)

docs/t-sql/functions/decryptbykey-transact-sql.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ DecryptByKey ( { 'ciphertext' | @ciphertext }
6161
Is a variable that contains data from which to generate an authenticator. Must match the value that was supplied to EncryptByKey.
6262

6363
## Return Types
64-
**varbinary** with a maximum size of 8,000 bytes.
64+
**varbinary** with a maximum size of 8,000 bytes.
65+
66+
Returns NULL if the symmetric key used for encrypting the data is not open or the *ciphertext* is NULL.
6567

6668
## Remarks
6769
DecryptByKey uses a symmetric key. This symmetric key must already be open in the database. There can be multiple keys open at the same time. You do not have to open the key immediately before decrypting the cipher text.

0 commit comments

Comments
 (0)