%3CLINGO-SUB%20id%3D%22lingo-sub-1427692%22%20slang%3D%22en-US%22%3EPart%204%20-%20SQL%20Server%20TDE%20and%20Extensible%20Key%20Management%20Using%20Azure%20Key%20Vault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1427692%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--1328515663%22%20id%3D%22toc-hId--1328515663%22%20id%3D%22toc-hId--1328515663%22%20id%3D%22toc-hId--1328515663%22%3EConfigure%20SQL%20Server%3C%2FH2%3E%0A%3CP%3EThis%20is%20%3CSTRONG%3EPart%3A%204%3C%2FSTRONG%3E%20of%20a%20%3CSTRONG%3E4-part%3C%2FSTRONG%3E%20blog%20series%3A%3C%2FP%3E%0A%3CP%3EAfter%20setting%20up%20Azure%20Active%20Directory%20and%20registering%20the%20AAD%20Application%20and%20additionally%20creating%20an%20Azure%20Key%20Vault%2C%20the%20next%20step%20is%20to%20put%20it%20all%20together%20in%20SQL%20Server%20where%20you%20can%20create%20credentials%20(to%20talk%20to%20Azure%20Key%20Vault)%2C%20create%20an%20asymmetric%20key%20and%20use%20that%20key%20to%20configure%2Fencrypt%20a%20database%20with%20TDE.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22Adrian_Rupp_0-1590520284345.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F194537i1B45F60DED360EDB%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Adrian_Rupp_0-1590520284345.png%22%20alt%3D%22Adrian_Rupp_0-1590520284345.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ERefer%20to%26nbsp%3B-ERR%3AREF-NOT-FOUND-B.%20Frequently%20Asked%20Questions%26nbsp%3Bto%20see%20a%20note%20about%20the%20minimum%20permission%20levels%20needed%20for%20each%20action%20in%20this%20section.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%201%3A%20Launch%20sqlcmd.exe%20or%20SQL%20Server%20Management%20Studio%20(SSMS)%3A%20%3C%2FSTRONG%3EIf%20you%20use%20SSMS%20open%20a%20query%20window%2C%20turn%20on%20SQLCMD%20mode%20(Menu%26gt%3BQuery%20%26gt%3B%20Click%20SQLCMD%20Mode)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%202%3A%20Configure%20SQL%20Server%20to%20use%20EKM%3C%2FSTRONG%3E%3A%20Execute%20the%20following%20Transact-SQL%20script%20to%20configure%20the%20Database%20Engine%20to%20use%20an%20EKM%20provider.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20Enable%20advanced%20options.%26nbsp%3B%0AUSE%20master%3B%26nbsp%3B%0AGO%26nbsp%3B%0AExec%20sp_configure%20'show%20advanced%20options'%2C%201%3B%26nbsp%3B%0AGO%26nbsp%3B%0ARECONFIGURE%3B%26nbsp%3B%0AGO%26nbsp%3B%0A%0A--%20Enable%20EKM%20provider%26nbsp%3B%0AExec%20sp_configure%20'EKM%20provider%20enabled'%2C%201%3B%26nbsp%3B%0AGO%26nbsp%3B%0ARECONFIGURE%3B%26nbsp%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%203%3A%20Register%20(create)%20the%20Connector%20as%20an%20EKM%20provider%20with%20SQL%20Server%3A%20%3C%2FSTRONG%3ECreate%20a%20cryptographic%20provider%2C%20using%20the%20SQL%20Server%20Connector%2C%20which%20is%20an%20EKM%20provider%20for%20the%20Azure%20Key%20Vault.%3CBR%20%2F%3EThis%20example%20uses%20the%20name%26nbsp%3BAzureKeyVault_EKM.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20CRYPTOGRAPHIC%20PROVIDER%20AzureKeyVault_EKM%26nbsp%3B%26nbsp%3B%0AFROM%20FILE%20%3D%20'C%3A%5CProgram%20Files%5CSQL%20Server%20Connector%20for%20Microsoft%20Azure%20Key%20Vault%5CMicrosoft.AzureKeyVaultService.EKM.dll'%3B%26nbsp%3B%0AGO%26nbsp%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CPRE%20class%3D%22lia-code-sample%20language-markdown%22%3E%3CCODE%3E%5BNOTE%5D%0AThe%20file%20path%20length%20cannot%20exceed%20256%20characters.%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3EStep%204%3A%20Setup%20a%20SQL%20Server%20credential%20for%20a%20SQL%20Server%20login%20to%20use%20the%20key%20vault%3A%3F%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3EA%20credential%20must%20be%20added%20to%20each%20login%20that%20will%20be%20performing%20encryption%20using%20a%20key%20from%20the%20Key%20Vault.%20This%20might%20include%3A%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A1%2C%26quot%3B335551620%26quot%3B%3A1%2C%26quot%3B335559685%26quot%3B%3A300%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20data-leveltext%3D%22%3F%22%20data-font%3D%22Symbol%22%20data-listid%3D%224%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3E%3CSPAN%20data-contrast%3D%22none%22%3EAn%20SQL%20Server%20administrator%20login%20who%20will%20use%20key%20vault%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3Ein%20order%20to%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3E%26nbsp%3Bsetup%20and%20manage%20SQL%20Server%20encryption%20scenarios.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233117%26quot%3B%3Atrue%2C%26quot%3B134233118%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A1%2C%26quot%3B335551620%26quot%3B%3A1%2C%26quot%3B335559685%26quot%3B%3A1020%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%20data-leveltext%3D%22%3F%22%20data-font%3D%22Symbol%22%20data-listid%3D%224%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3E%3CSPAN%20data-contrast%3D%22none%22%3EOther%20SQL%20Server%20logins%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3Esuch%20as%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3E%26nbsp%3Bdedicated%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3ESecurity%20%26amp%3B%20Compliance%20Administrators%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3Ewho%20might%20enable%20Transparent%20Data%20Encryption%20(TDE)%2C%20or%20other%20SQL%20Server%20encryption%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3Efeatures%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3E.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233117%26quot%3B%3Atrue%2C%26quot%3B134233118%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A1%2C%26quot%3B335551620%26quot%3B%3A1%2C%26quot%3B335559685%26quot%3B%3A1020%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22none%22%3EThere%20is%20one-to-one%20mapping%20between%20credentials%20and%20logins.%20That%20is%2C%20each%20login%20must%20have%20a%20unique%20credential.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A1%2C%26quot%3B335551620%26quot%3B%3A1%2C%26quot%3B335559685%26quot%3B%3A300%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22none%22%3EModify%20the%20Transact-SQL%20script%20below%20in%20the%20following%20ways%3A%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A1%2C%26quot%3B335551620%26quot%3B%3A1%2C%26quot%3B335559685%26quot%3B%3A300%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20data-leveltext%3D%22%3F%22%20data-font%3D%22Symbol%22%20data-listid%3D%225%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%222%22%20data-aria-level%3D%221%22%3E%3CSPAN%20data-contrast%3D%22none%22%3EEdit%20the%20IDENTITY%20argument%20(%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3EMyAAD%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3E-EKM-AKV-%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3EDemoKeyVault%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22none%22%3E)%20to%20point%20to%20your%20Azure%20Key%20Vault.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233117%26quot%3B%3Atrue%2C%26quot%3B134233118%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A1%2C%26quot%3B335551620%26quot%3B%3A1%2C%26quot%3B335559685%26quot%3B%3A1020%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%20data-leveltext%3D%22o%22%20data-font%3D%22Courier%20New%22%20data-listid%3D%225%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%222%22%3E%3CSPAN%20data-contrast%3D%22none%22%3EIf%20you're%20using%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3Eglobal%20Azure%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3E%2C%20replace%20the%20IDENTITY%20argument%20with%20the%20name%20of%20your%20Azure%20Key%20Vault%20from%20Part%3A%202.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233117%26quot%3B%3Atrue%2C%26quot%3B134233118%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A1%2C%26quot%3B335551620%26quot%3B%3A1%2C%26quot%3B335559685%26quot%3B%3A1740%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%20data-leveltext%3D%22o%22%20data-font%3D%22Courier%20New%22%20data-listid%3D%225%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%222%22%3E%3CSPAN%20data-contrast%3D%22none%22%3EIf%20you're%20using%20a%20%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3Eprivate%20Azure%20cloud%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3E(ex.%20Azure%20Government%2C%20Azure%20China%2C%20or%20Azure%20Germany)%2C%20replace%20the%20IDENTITY%20argument%20with%20the%20Vault%20URI%20that%20is%20returned%20in%20Part%202%2C%20Step%206.%20Do%20not%20include%20%22https%3A%2F%2F%22%20in%20the%20Vault%20URI.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233117%26quot%3B%3Atrue%2C%26quot%3B134233118%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A1%2C%26quot%3B335551620%26quot%3B%3A1%2C%26quot%3B335559685%26quot%3B%3A1740%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%20data-leveltext%3D%22%3F%22%20data-font%3D%22Symbol%22%20data-listid%3D%225%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3E%3CSPAN%20data-contrast%3D%22none%22%3EReplace%20the%20first%20part%20of%20the%20SECRET%20argument%20with%20the%20Azure%20Active%20Directory%20%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3EClient%20ID%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3Efrom%20Part%202.%20In%20this%20example%2C%20the%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3EClient%20ID%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22none%22%3Eis%209A57CBC54C4C40E2B517EA677E0EFA00.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233117%26quot%3B%3Atrue%2C%26quot%3B134233118%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A1%2C%26quot%3B335551620%26quot%3B%3A1%2C%26quot%3B335559685%26quot%3B%3A1020%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markdown%22%3E%3CCODE%3E%5BIMPORTANT%5D%26nbsp%3B%0AYou%20must%20remove%20the%20hyphens%20from%20the%20App%20(Client)%20ID.%20%0A%0AComplete%20the%20second%20part%20of%20the%20SECRET%20argument%20with%20Client%20Secret%20from%20Part%3A%202.%20%0AIn%20this%20example%20the%20Client%20Secret%20from%20Part%3A%202%20is%20%0A(Example%3A%3F08%3Ak%3F%5B%3AXEZFxcwIPvVVZhTjHWXm7w1%3Fm).%20%0AThe%20final%20string%20for%20the%20SECRET%20argument%20will%20be%20a%20long%20sequence%20of%20letters%20and%20numbers%2C%20with%20no%20hyphens.%20%3C%2FCODE%3E%3C%2FPRE%3E%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3EUSE%20master%3B%26nbsp%3B%0ACREATE%20CREDENTIAL%20sysadmin_ekm_cred%26nbsp%3B%26nbsp%3B%0AWITH%20IDENTITY%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3D%20'ConstosoKeyVaultKeyVault'%2C%26nbsp%3B%20--%20for%20public%20Azure%0A--%20WITH%20IDENTITY%20%3D%20'ContosoEKMKeyVault.vault.usgovcloudapi.net'%2C%20--%20for%20Azure%20Government%0A--%20WITH%20IDENTITY%20%3D%20'ContosoEKMKeyVault.vault.azure.cn'%2C--%20for%20Azure%20China%0A--%20WITH%20IDENTITY%20%3D%20'ContosoEKMKeyVault.vault.microsoftazure.de'%2C%20--%20for%20Azure%20Germany%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20--%26lt%3B----Application%20(Client)%20ID%20---%26gt%3B%26lt%3B--AAD%20App%20(Client)%20ID%20Secret--%26gt%3B%0A--SECRET%20%3D%20'9A57CBC54C4C40E2B517EA677E0EFA0008%3Ak%3F%5B%3AXEZFxcwIPvVVZhTjHWXm7w1%3Fm'%26nbsp%3B%26nbsp%3B%0ASECRET%20%3D%20'%3CAPPID%20guid%3D%22%22%20with%3D%22%22%20no%3D%22%22%20dashes%3D%22%22%20from%3D%22%22%20aad%3D%22%22%3E%3CCLIENT%20secret%3D%22%22%20from%3D%22%22%20aad%3D%22%22%3E'%0AFOR%20CRYPTOGRAPHIC%20PROVIDER%20AzureKeyVault_EKM%3B%26nbsp%3B%3C%2FCLIENT%3E%3C%2FAPPID%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%205%3A%20Add%20Credential%20to%20your%20Windows%20Login%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20Add%20the%20credential%20to%20the%20SQL%20Server%20administrator's%20domain%20login%26nbsp%3B%26nbsp%3B%0AALTER%20LOGIN%20%5B%3CDOMAIN%3E%5C%3CLOGIN%3E%5D%26nbsp%3B%0AADD%20CREDENTIAL%20sysadmin_ekm_cred%3B%26nbsp%3B%3C%2FLOGIN%3E%3C%2FDOMAIN%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%206%3A%20Open%20your%20Azure%20Key%20Vault%20key%20in%20SQL%20Server%3A%20%3C%2FSTRONG%3EWhether%20you%20created%20a%20new%20key%2C%20or%20imported%20an%20asymmetric%20key%20as%20described%20in%20-ERR%3AREF-NOT-FOUND-Part%3APS2%20or%20-ERR%3AREF-NOT-FOUND-Part%3AAP3%2C%20you%20will%20need%20to%20open%20the%20key.%20Open%20the%20key%20by%20providing%20your%20key%20name%20in%20the%20following%26nbsp%3B%20Transact-SQL%20script.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EReplace%26nbsp%3B%3CSTRONG%3EEKMSampleASYKey%3C%2FSTRONG%3E%20with%20the%20name%20you'd%20like%20the%20key%20to%20have%20in%20SQL%20Server%3C%2FLI%3E%0A%3CLI%3EReplace%26nbsp%3B%3CSTRONG%3EConstosoKeyVaultRSAKey%3C%2FSTRONG%3E%20with%20the%20name%20of%20your%20key%20in%20Azure%20Key%20Vault.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20ASYMMETRIC%20KEY%20EKMSampleASYKey%26nbsp%3B%26nbsp%3B%0AFROM%20PROVIDER%20%5BAzureKeyVault_EKM%5D%26nbsp%3B%0AWITH%20PROVIDER_KEY_NAME%20%3D%20'ConstosoKeyVaultRSAKey'%2C%26nbsp%3B%0ACREATION_DISPOSITION%20%3D%20OPEN_EXISTING%3B%26nbsp%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%207%3A%20Create%20a%20new%20Login%20from%20ASYMMETRIC%26nbsp%3BKEY%20in%20SQL%20Server%3A%3C%2FSTRONG%3E%26nbsp%3BThe%20new%20login%20can%20now%20be%20created%20using%20the%20asymmetric%20key%20creates%20in%20step%206.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--Create%20a%20Login%20that%20will%20associate%20the%20asymmetric%20key%20to%20this%20login%0ACREATE%20LOGIN%20TDE_Login%0AFROM%20ASYMMETRIC%20KEY%20EKMSampleASYKey%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%208%3A%20Create%20a%20new%20Login%20from%20ASYMMETRIC%26nbsp%3BKEY%20in%20SQL%20Server%3A%3C%2FSTRONG%3E%26nbsp%3BDrop%20the%20credential%20mapping%20from%20Step%205%20so%20the%20credential%20can%20be%20mapped%20to%20the%20new%20login.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--Now%20drop%20the%20credential%20mapping%20from%20the%20original%20association%0AALTER%20LOGIN%20%5B%3CDOMAIN%3E%5C%3CLOGIN%3E%5D%0ADROP%20CREDENTIAL%20sysadmin_ekm_cred%3B%3C%2FLOGIN%3E%3C%2FDOMAIN%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%209%3A%20Alter%20the%20new%20Login%3A%3C%2FSTRONG%3E%26nbsp%3BAlter%20the%20new%20Login%20and%20map%20the%20EKM%20credential%20to%20the%20new%20login.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--Now%20drop%20the%20credential%20mapping%20from%20the%20original%20association%0AALTER%20LOGIN%20TDE_Login%0AADD%20CREDENTIAL%20sysadmin_ekm_cred%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%2010%3A%20Create%20Test%20Database%3A%3C%2FSTRONG%3E%26nbsp%3BCreate%20a%20test%20database%20that%20will%20be%20encrypted%20with%20the%20Azure%20Key%20Vault%20(Key).%20(Or%20use%20an%20existing%20database%20-%20make%20sure%20you%20have%20a%20good%2Fcurrent%20unencrypted%20backup%20before%20turning%20on%20TDE)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--Create%20a%20test%20db%20that%20will%20be%20encrypted%20with%20the%20Azure%20KeyVault%20(Key)%0ACREATE%20DATABASE%20TestTDE%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%2011%3A%20Create%20a%20database%20encryption%20Key%3C%2FSTRONG%3E%26nbsp%3BCreate%20an%20ENCRYPTION%20KEY%20using%20the%20ASYMMETRIC%20KEY%20(EKMSampleASYKey)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--Create%20an%20ENCRYPTION%20KEY%20using%20the%20ASYMMETRIC%20KEY%20(EKMSampleASYKey)%0ACREATE%20DATABASE%20ENCRYPTION%20KEY%26nbsp%3B%26nbsp%3B%0AWITH%20ALGORITHM%20%3D%20AES_256%26nbsp%3B%26nbsp%3B%0AENCRYPTION%20BY%20SERVER%20ASYMMETRIC%20KEY%20EKMSampleASYKey%3B%26nbsp%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%2012%3A%20%26nbsp%3BEncrypt%20the%20test%20database%20%3C%2FSTRONG%3EEnable%20TDE%20by%20setting%20ENCRYPTION%20ON%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--Enable%20TDE%20by%20setting%20ENCRYPTION%20ON%0AALTER%20DATABASE%20TestTDE%26nbsp%3B%26nbsp%3B%0ASET%20ENCRYPTION%20ON%3B%26nbsp%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%2013%3A%20Validate%20TDE%20is%20ON%20and%20has%20encrypted%20the%20database%3A%20%3C%2FSTRONG%3ESQL%20Server%20has%20a%20DMV%20that%20will%20show%20if%20encryption%20has%20been%20enabled%20ad%20the%20state%20of%20the%20encrypted%20database.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Eselect%20db_name(database_id)%20AS%20DB%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2Cpercent_complete%20AS%20percent_complete%20%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2Cencryption_state%20AS%20encryption_state%0Afrom%20sys.dm_database_encryption_keys%0A%2F*%0A0%20%3D%20No%20database%20encryption%20key%20present%2C%20no%20encryption%0A1%20%3D%20Unencrypted%0A2%20%3D%20Encryption%20in%20progress%0A3%20%3D%20Encrypted%0A4%20%3D%20Key%20change%20in%20progress%0A5%20%3D%20Decryption%20in%20progress%0A6%20%3D%20Protection%20change%20in%20progress%0A*%2F%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%2014%3A%20Cleanup%20test%20objects%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20CLEAN%20UP%0AUSE%20Master%0AALTER%20DATABASE%20%5BTestTDE%5D%20SET%26nbsp%3B%20SINGLE_USER%20WITH%20ROLLBACK%20IMMEDIATE%0ADROP%20DATABASE%20%5BTestTDE%5D%0A%0AALTER%20LOGIN%20%5BTDE_Login%5D%20DROP%20CREDENTIAL%20%5Bsysadmin_ekm_cred%5D%0ADROP%20LOGIN%20%5BTDE_Login%5D%0A%0A--ALTER%20LOGIN%20%5Bdomain%5Clogin%5D%20DROP%20CREDENTIAL%20%5Bsysadmin_ekm_cred%5D%0ADROP%20CREDENTIAL%20%5Bsysadmin_ekm_cred%5D%0A%0AUSE%20MASTER%0ADROP%20ASYMMETRIC%20KEY%20%5BEKMSampleASYKey%5D%0ADROP%20CRYPTOGRAPHIC%20PROVIDER%20%5BAzureKeyVault_EKM%5D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1158997170%22%20id%3D%22toc-hId-1158997170%22%20id%3D%22toc-hId-1158997170%22%20id%3D%22toc-hId-1158997170%22%3EConclusion%3C%2FH2%3E%0A%3CP%3EConfiguring%20SQL%20Server%20with%20the%20SQL%20Connector%2C%20registering%20an%20Azure%20Active%20Directory%20application%2C%20creating%20RSA%20key%20in%20Azure%20Key%20Vault%26nbsp%3B%20and%20creating%20the%20SQL%20credentials%2C%20asymmetric%20key%2C%20and%20enabling%20TDE%20are%20the%20final%20steps%20to%20enable%20TDE%20to%20use%20Extensible%20Key%20Management%20(EKM)%20and%20Azure%20Key%20Vault%20(AKV)%20for%20encryption.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELive%20secure%20and%20prosper!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdrian%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--648457293%22%20id%3D%22toc-hId--648457293%22%20id%3D%22toc-hId--648457293%22%20id%3D%22toc-hId--648457293%22%3ENext%20steps%3C%2FH2%3E%0A%3CTABLE%20width%3D%22618%22%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%20colspan%3D%222%22%20width%3D%22616.667px%22%20height%3D%2255px%22%20class%3D%22lia-align-center%22%3E%3CFONT%20size%3D%223%22%3ESQL%20Server%20TDE%20with%20EKM%20Using%20Azure%20Key%20Vault%20%E2%80%93%20-ERR%3AREF-NOT-FOUND-%3CU%3EIntro%3C%2FU%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20colspan%3D%222%22%20width%3D%22616.667px%22%20height%3D%2255px%22%20class%3D%22lia-align-center%22%3E%0A%3CP%3E%3CFONT%20color%3D%22%23993300%22%3ESQL%20Server%20Connector%20for%20Microsoft%20Azure%20Key%20Vault%20(aka%3A%20SQL%20Server%20Connector)%20%E2%80%93%20%3CU%3EPart%3A%201%3C%2FU%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22295.556px%22%20height%3D%2230px%22%20class%3D%22lia-align-center%22%3E%0A%3CP%3E%3CFONT%20color%3D%22%23800080%22%3E%3CSTRONG%3EAzure%20Portal%20Method%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22321.111px%22%20height%3D%2230px%22%20class%3D%22lia-align-center%22%3E%0A%3CP%3E%3CFONT%20color%3D%22%23339966%22%3E%3CSTRONG%3EPowerShell%20Method%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22295.556px%22%20height%3D%2278px%22%3E%0A%3CP%20data-unlink%3D%22true%22%3E%3CFONT%20color%3D%22%23800080%22%3ESet%20up%20an%20Azure%20Active%20Directory%20Service%20Principal%20%E2%80%93%20%3CU%3EPart%3A%20AP2%3C%2FU%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20rowspan%3D%222%22%20width%3D%22321.111px%22%20height%3D%22118px%22%3E%0A%3CP%20data-unlink%3D%22true%22%3E%3CFONT%20color%3D%22%23339966%22%3ESetup%20Azure%20Active%20Directory%20Service%20Principal%20and%20%26nbsp%3BAzure%20Key%20Vault%20(one%20script)%20%E2%80%93%20%3CU%3EPart%3A%20PS2%3C%2FU%3E%26nbsp%3B%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23339966%22%3E%3CEM%3EThis%20script%20combines%20Part%3AAP2%20%26amp%3B%20Part%3AAP3%3C%2FEM%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22295.556px%22%20height%3D%2240px%22%3E%0A%3CP%20data-unlink%3D%22true%22%3E%3CFONT%20color%3D%22%23800080%22%3ECreate%20an%20Azure%20Key%20Vault%20%E2%80%93%20%3CU%3EPart%3A%20AP3%3C%2FU%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20colspan%3D%222%22%20width%3D%22616.667px%22%20height%3D%2230px%22%3E%0A%3CP%20class%3D%22lia-align-center%22%20data-unlink%3D%22true%22%3E%3CFONT%20color%3D%22%23000080%22%3EConfigure%20SQL%20Server%20TDE%20EKM%20using%20AKV%20%E2%80%93%20Part%3A%204%3C%2FFONT%3E%26nbsp%3B%26nbsp%3B(this%26nbsp%3Bdocument)%26nbsp%3B%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%20class%3D%22lia-align-left%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-left%22%3E%3CSPAN%3EDownload%20the%20scripts%20for%20PowerShell%20and%20SQLCMD%20here%3A%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1427692%22%20slang%3D%22en-US%22%3E%3CP%3EConfigure%20SQL%20Server%3CBR%20%2F%3EThis%20is%20%3CSTRONG%3EPart%3A%204%20(SQL)%3C%2FSTRONG%3E%20of%20a%20%3CSTRONG%3E4-part%3C%2FSTRONG%3E%20blog%20series%3A%3C%2FP%3E%0A%3CP%3EAfter%20setting%20up%20Azure%20Active%20Directory%20and%20registering%20the%20AAD%20Application%20and%20additionally%20creating%20an%20Azure%20Key%20Vault%2C%20the%20next%20step%20is%20to%20put%20it%20all%20together%20in%20SQL%20Server%20where%20you%20can%20create%20credentials%20(to%20talk%20to%20AKV)%2C%20create%20an%20asymmetric%20key%20and%20use%20that%20key%20to%20configure%2Fencrypt%20a%20database%20with%20TDE.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1427692%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerSecurity%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1428648%22%20slang%3D%22en-US%22%3ERe%3A%20Part%204%20-%20SQL%20Server%20TDE%20and%20Extensible%20Key%20Management%20Using%20Azure%20Key%20Vault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1428648%22%20slang%3D%22en-US%22%3E%3CP%3EGetting%20this%20error%20on%20Step%206.%20Any%20idea%20what%20could%20be%20wrong.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMsg%2033028%2C%20Level%2016%2C%20State%201%2C%20Line%2038%3CBR%20%2F%3ECannot%20open%20session%20for%20cryptographic%20provider%20'AzureKeyVault_EKM'.%20Provider%20error%20code%3A%203900.%20(Provider%20Error%20-%20No%20explanation%20is%20available%2C%20consult%20EKM%20Provider%20for%20details)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1428685%22%20slang%3D%22en-US%22%3ERe%3A%20Part%204%20-%20SQL%20Server%20TDE%20and%20Extensible%20Key%20Management%20Using%20Azure%20Key%20Vault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1428685%22%20slang%3D%22en-US%22%3E%3CP%3EFrom%20my%20experience%2C%20I%20can%20reproduce%20this%20error%20if%20you%20try%20to%20execute%20the%20TSQL%20code%20to%20create%20the%20Credentials%20and%20ASYMMETRIC%20KEYS%20%3CSTRONG%3Ebefore%3C%2FSTRONG%3E%20the%20Azure%20items%20are%20created%2C%20this%20error%20occurs.%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20not%20already%20done%20so%2C%20I%20would%20suggest%20going%20through%20the%20PowerShell%20script%20(%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fsql-server%2Fpart-2-powershell-sql-server-tde-and-extensible-key-management%2Fba-p%2F1427682%22%20target%3D%22_self%22%3EPart%3APS2%3C%2FA%3E)%20first%20and%20make%20sure%20everything%20is%20in%20order%20before%20attempting%20the%20SQL%20Server%20portion%20of%20the%20solution.%20If%20you%20have%20already%20gone%20through%20the%20Azure%20setup%2C%20I%20would%20double-check%20the%20Azure%20Key%20Vault%20names%20to%20make%20sure%20you%20are%20are%20trying%20to%20reference%20the%20correct%20objects%20in%20Azure.%3C%2FP%3E%0A%3CP%3EI'm%20working%20on%20getting%20the%20full%20set%20of%20error%20codes%20published%20so%20the%20error%20messages%20are%20less%20cryptic.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHope%20this%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

Configure SQL Server

This is Part: 4 of a 4-part blog series:

After setting up Azure Active Directory and registering the AAD Application and additionally creating an Azure Key Vault, the next step is to put it all together in SQL Server where you can create credentials (to talk to Azure Key Vault), create an asymmetric key and use that key to configure/encrypt a database with TDE.

Adrian_Rupp_0-1590520284345.png

Refer to B. Frequently Asked Questions to see a note about the minimum permission levels needed for each action in this section.

Step 1: Launch sqlcmd.exe or SQL Server Management Studio (SSMS): If you use SSMS open a query window, turn on SQLCMD mode (Menu>Query > Click SQLCMD Mode)

 

Step 2: Configure SQL Server to use EKM: Execute the following Transact-SQL script to configure the Database Engine to use an EKM provider.

 

-- Enable advanced options. 
USE master; 
GO 
Exec sp_configure 'show advanced options', 1; 
GO 
RECONFIGURE; 
GO 

-- Enable EKM provider 
Exec sp_configure 'EKM provider enabled', 1; 
GO 
RECONFIGURE; 

 

Step 3: Register (create) the Connector as an EKM provider with SQL Server: Create a cryptographic provider, using the SQL Server Connector, which is an EKM provider for the Azure Key Vault.
This example uses the name AzureKeyVault_EKM.

 

CREATE CRYPTOGRAPHIC PROVIDER AzureKeyVault_EKM  
FROM FILE = 'C:\Program Files\SQL Server Connector for Microsoft Azure Key Vault\Microsoft.AzureKeyVaultService.EKM.dll'; 
GO 
[NOTE]
The file path length cannot exceed 256 characters.

 

Step 4: Setup a SQL Server credential for a SQL Server login to use the key vault:?A credential must be added to each login that will be performing encryption using a key from the Key Vault. This might include: 

  • An SQL Server administrator login who will use key vault in order to setup and manage SQL Server encryption scenarios. 
  • Other SQL Server logins such as dedicated Security & Compliance Administrators who might enable Transparent Data Encryption (TDE), or other SQL Server encryption features. 

There is one-to-one mapping between credentials and logins. That is, each login must have a unique credential. 

Modify the Transact-SQL script below in the following ways: 

  • Edit the IDENTITY argument (MyAAD-EKM-AKV-DemoKeyVault) to point to your Azure Key Vault. 
  • If you're using global Azure, replace the IDENTITY argument with the name of your Azure Key Vault from Part: 2. 
  • If you're using a private Azure cloud (ex. Azure Government, Azure China, or Azure Germany), replace the IDENTITY argument with the Vault URI that is returned in Part 2, Step 6. Do not include "https://" in the Vault URI. 
  • Replace the first part of the SECRET argument with the Azure Active Directory Client ID from Part 2. In this example, the Client ID is 9A57CBC54C4C40E2B517EA677E0EFA00. 

 

[IMPORTANT] 
You must remove the hyphens from the App (Client) ID. 

Complete the second part of the SECRET argument with Client Secret from Part: 2. 
In this example the Client Secret from Part: 2 is 
(Example:?08:k?[:XEZFxcwIPvVVZhTjHWXm7w1?m). 
The final string for the SECRET argument will be a long sequence of letters and numbers, with no hyphens. 
USE master; 
CREATE CREDENTIAL sysadmin_ekm_cred  
WITH IDENTITY    = 'ConstosoKeyVaultKeyVault',  -- for public Azure
-- WITH IDENTITY = 'ContosoEKMKeyVault.vault.usgovcloudapi.net', -- for Azure Government
-- WITH IDENTITY = 'ContosoEKMKeyVault.vault.azure.cn',-- for Azure China
-- WITH IDENTITY = 'ContosoEKMKeyVault.vault.microsoftazure.de', -- for Azure Germany
         --<----Application (Client) ID ---><--AAD App (Client) ID Secret-->
--SECRET = '9A57CBC54C4C40E2B517EA677E0EFA0008:k?[:XEZFxcwIPvVVZhTjHWXm7w1?m'  
SECRET = '<AppID GUID with no dashes from AAD><Client Secret From AAD>'
FOR CRYPTOGRAPHIC PROVIDER AzureKeyVault_EKM; 

 

Step 5: Add Credential to your Windows Login

 

-- Add the credential to the SQL Server administrator's domain login  
ALTER LOGIN [<domain>\<login>] 
ADD CREDENTIAL sysadmin_ekm_cred; 

 

Step 6: Open your Azure Key Vault key in SQL Server: Whether you created a new key, or imported an asymmetric key as described in Part:PS2 or Part:AP3, you will need to open the key. Open the key by providing your key name in the following  Transact-SQL script.

  • Replace EKMSampleASYKey with the name you'd like the key to have in SQL Server
  • Replace ConstosoKeyVaultRSAKey with the name of your key in Azure Key Vault.

 

CREATE ASYMMETRIC KEY EKMSampleASYKey  
FROM PROVIDER [AzureKeyVault_EKM] 
WITH PROVIDER_KEY_NAME = 'ConstosoKeyVaultRSAKey', 
CREATION_DISPOSITION = OPEN_EXISTING; 

 

Step 7: Create a new Login from ASYMMETRIC KEY in SQL Server: The new login can now be created using the asymmetric key creates in step 6.

 

--Create a Login that will associate the asymmetric key to this login
CREATE LOGIN TDE_Login
FROM ASYMMETRIC KEY EKMSampleASYKey;

 

Step 8: Create a new Login from ASYMMETRIC KEY in SQL Server: Drop the credential mapping from Step 5 so the credential can be mapped to the new login.

 

--Now drop the credential mapping from the original association
ALTER LOGIN [<domain>\<login>]
DROP CREDENTIAL sysadmin_ekm_cred;

 

Step 9: Alter the new Login: Alter the new Login and map the EKM credential to the new login.

 

--Now drop the credential mapping from the original association
ALTER LOGIN TDE_Login
ADD CREDENTIAL sysadmin_ekm_cred;

 

Step 10: Create Test Database: Create a test database that will be encrypted with the Azure Key Vault (Key). (Or use an existing database - make sure you have a good/current unencrypted backup before turning on TDE)

 

--Create a test db that will be encrypted with the Azure KeyVault (Key)
CREATE DATABASE TestTDE

 

Step 11: Create a database encryption Key Create an ENCRYPTION KEY using the ASYMMETRIC KEY (EKMSampleASYKey)

 

--Create an ENCRYPTION KEY using the ASYMMETRIC KEY (EKMSampleASYKey)
CREATE DATABASE ENCRYPTION KEY  
WITH ALGORITHM = AES_256  
ENCRYPTION BY SERVER ASYMMETRIC KEY EKMSampleASYKey; 

 

Step 12:  Encrypt the test database Enable TDE by setting ENCRYPTION ON 

 

--Enable TDE by setting ENCRYPTION ON
ALTER DATABASE TestTDE  
SET ENCRYPTION ON; 

 

Step 13: Validate TDE is ON and has encrypted the database: SQL Server has a DMV that will show if encryption has been enabled ad the state of the encrypted database.

 

select db_name(database_id) AS DB
       ,percent_complete AS percent_complete 
       ,encryption_state AS encryption_state
from sys.dm_database_encryption_keys
/*
0 = No database encryption key present, no encryption
1 = Unencrypted
2 = Encryption in progress
3 = Encrypted
4 = Key change in progress
5 = Decryption in progress
6 = Protection change in progress
*/

 

Step 14: Cleanup test objects

 

-- CLEAN UP
USE Master
ALTER DATABASE [TestTDE] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE [TestTDE]

ALTER LOGIN [TDE_Login] DROP CREDENTIAL [sysadmin_ekm_cred]
DROP LOGIN [TDE_Login]

--ALTER LOGIN [domain\login] DROP CREDENTIAL [sysadmin_ekm_cred]
DROP CREDENTIAL [sysadmin_ekm_cred]

USE MASTER
DROP ASYMMETRIC KEY [EKMSampleASYKey]
DROP CRYPTOGRAPHIC PROVIDER [AzureKeyVault_EKM]

 

Conclusion

Configuring SQL Server with the SQL Connector, registering an Azure Active Directory application, creating RSA key in Azure Key Vault  and creating the SQL credentials, asymmetric key, and enabling TDE are the final steps to enable TDE to use Extensible Key Management (EKM) and Azure Key Vault (AKV) for encryption.

 

Live secure and prosper!

 

Adrian

Next steps

SQL Server TDE with EKM Using Azure Key Vault – Intro 

SQL Server Connector for Microsoft Azure Key Vault (aka: SQL Server Connector) – Part: 1

Azure Portal Method

PowerShell Method

Set up an Azure Active Directory Service Principal – Part: AP2 

Setup Azure Active Directory Service Principal and  Azure Key Vault (one script) – Part: PS2  

This script combines Part:AP2 & Part:AP3

Create an Azure Key Vault – Part: AP3

Configure SQL Server TDE EKM using AKV – Part: 4  (this document) 

 

Download the scripts for PowerShell and SQLCMD here:

2 Comments
Visitor

Getting this error on Step 6. Any idea what could be wrong.

 

Msg 33028, Level 16, State 1, Line 38
Cannot open session for cryptographic provider 'AzureKeyVault_EKM'. Provider error code: 3900. (Provider Error - No explanation is available, consult EKM Provider for details)

Microsoft

From my experience, I can reproduce this error if you try to execute the TSQL code to create the Credentials and ASYMMETRIC KEYS before the Azure items are created, this error occurs.

If you have not already done so, I would suggest going through the PowerShell script (Part:PS2) first and make sure everything is in order before attempting the SQL Server portion of the solution. If you have already gone through the Azure setup, I would double-check the Azure Key Vault names to make sure you are are trying to reference the correct objects in Azure.

I'm working on getting the full set of error codes published so the error messages are less cryptic.

 

Hope this helps.