Share via


CertificateClient class

要與 KeyVault 憑證功能互動的用戶端

建構函式

CertificateClient(string, TokenCredential, CertificateClientOptions)

建立 CertificateClient 的實例。

屬性

vaultUrl

保存庫的基底 URL

方法

backupCertificate(string, OperationOptions)

要求將指定憑證的備份下載至用戶端。 將會下載所有版本的憑證。 這項作業需要憑證/備份許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
const backup = await client.backupCertificate("MyCertificate");

產生憑證的備份

beginCreateCertificate(string, CertificatePolicy, BeginCreateCertificateOptions)

建立新的憑證。 如果這是第一個版本,則會建立憑證資源。 此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候,直到憑證完全復原為止。

注意: 傳送 Self 作為 issuerName 憑證原則的 將會建立自我簽署憑證。

此作業須有憑證/建立權限。

使用方式範例:

const client = new CertificateClient(url, credentials);
const certificatePolicy = {
  issuerName: "Self",
  subject: "cn=MyCert"
};
const createPoller = await client.beginCreateCertificate("MyCertificate", certificatePolicy);

// The pending certificate can be obtained by calling the following method:
const pendingCertificate = createPoller.getResult();

// Serializing the poller
const serialized = createPoller.toString();

// A new poller can be created with:
// const newPoller = await client.beginCreateCertificate("MyCertificate", certificatePolicy, { resumeFrom: serialized });

// Waiting until it's done
const certificate = await createPoller.pollUntilDone();
console.log(certificate);

建立憑證

beginDeleteCertificate(string, CertificatePollerOptions)

DELETE 作業適用于儲存在 Azure 金鑰保存庫中的任何憑證。 DELETE 無法套用至個別版本的憑證。 此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候,直到憑證完全復原為止。

這項作業需要憑證/刪除許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const createPoller = await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
await createPoller.pollUntilDone();

const deletePoller = await client.beginDeleteCertificate("MyCertificate");

// Serializing the poller
const serialized = deletePoller.toString();

// A new poller can be created with:
// const newPoller = await client.beginDeleteCertificate("MyCertificate", { resumeFrom: serialized });

// Waiting until it's done
const deletedCertificate = await deletePoller.pollUntilDone();
console.log(deletedCertificate);

從指定的金鑰保存庫刪除憑證。

beginRecoverDeletedCertificate(string, CertificatePollerOptions)

復原指定保存庫中已刪除的憑證。 此作業只能在已啟用虛刪除的保存庫上執行。 此作業 此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候憑證完全復原。

這項作業需要憑證/復原許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);

const deletePoller = await client.beginDeleteCertificate("MyCertificate");
await deletePoller.pollUntilDone();

const recoverPoller = await client.beginRecoverDeletedCertificate("MyCertificate");

// Serializing the poller
const serialized = deletePoller.toString();

// A new poller can be created with:
// const newPoller = await client.beginRecoverDeletedCertificate("MyCertificate", { resumeFrom: serialized });

// Waiting until it's done
const certificate = await recoverPoller.pollUntilDone();
console.log(certificate);

復原已刪除的憑證

createIssuer(string, string, CreateIssuerOptions)

createIssuer 作業會新增或更新指定的憑證簽發者。 這項作業需要憑證/setissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Test");

設定指定的憑證簽發者。

deleteCertificateOperation(string, OperationOptions)

刪除所建立之指定憑證的建立作業。 不再建立憑證。 這項作業需要憑證/更新許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
await client.deleteCertificateOperation("MyCertificate");
await client.getCertificateOperation("MyCertificate"); // Throws error: Pending certificate not found: "MyCertificate"

刪除憑證的作業

deleteContacts(OperationOptions)

刪除所有憑證連絡人。 這項作業需要憑證/managecontacts 許可權。

使用方式範例:

let client = new CertificateClient(url, credentials);
await client.setContacts([{
  email: "b@b.com",
  name: "b",
  phone: "222222222222"
}]);
await client.deleteContacts();

刪除所有憑證連絡人

deleteIssuer(string, OperationOptions)

deleteIssuer 作業會永久從保存庫移除指定的憑證簽發者。 這項作業需要憑證/manageissuers/deleteissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Provider");
await client.deleteIssuer("IssuerName");

刪除指定的憑證簽發者。

getCertificate(string, OperationOptions)

取得特定憑證中可用的最新資訊,包括憑證的原則。 這項作業需要憑證/取得許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const poller = await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
await poller.pollUntilDone();
const certificate = await client.getCertificate("MyCertificate");
console.log(certificate);

從憑證的名稱擷取憑證, (包含憑證原則)

getCertificateOperation(string, CertificatePollerOptions)

取得與指定憑證相關聯的建立作業。 這項作業需要憑證/取得許可權。 此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候,直到憑證完全復原為止。

使用方式範例:

const client = new CertificateClient(url, credentials);
const createPoller = await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});

const poller = await client.getCertificateOperation("MyCertificate");
const pendingCertificate = poller.getResult();

const certificateOperation = poller.getOperationState().certificateOperation;
console.log(certificateOperation);

取得憑證的輪詢器作業

getCertificatePolicy(string, OperationOptions)

getCertificatePolicy 作業會傳回指定金鑰保存庫中的指定憑證原則資源。 這項作業需要憑證/取得許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
const policy = await client.getCertificatePolicy("MyCertificate");
console.log(policy);

取得憑證的原則

getCertificateVersion(string, string, OperationOptions)

取得特定版本上特定憑證的相關資訊。 它不會傳回憑證的原則。 這項作業需要憑證/取得許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const poller = await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
await poller.pollUntilDone();
const certificateWithPolicy = await client.getCertificate("MyCertificate");
const certificate = await client.getCertificateVersion("MyCertificate", certificateWithPolicy.properties.version!);
console.log(certificate);

從憑證的名稱和指定的版本擷取憑證

getContacts(OperationOptions)

傳回指定之金鑰保存庫中的憑證連絡人資源集。 這項作業需要憑證/managecontacts 許可權。

使用方式範例:

let client = new CertificateClient(url, credentials);
await client.setContacts([{
  email: "b@b.com",
  name: "b",
  phone: "222222222222"
}]);
const contacts = await client.getContacts();
console.log(contacts);

設定憑證連絡人。

getDeletedCertificate(string, OperationOptions)

擷取已刪除的憑證資訊及其屬性,例如保留間隔、排程的永久刪除和目前的刪除復原層級。 這項作業需要憑證/取得許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const deletedCertificate = await client.getDeletedCertificate("MyDeletedCertificate");
console.log("Deleted certificate:", deletedCertificate);

取得已刪除的憑證

getIssuer(string, OperationOptions)

getIssuer 作業會傳回指定金鑰保存庫中的指定憑證簽發者資源。 這項作業需要憑證/manageissuers/getissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Test");
const certificateIssuer = await client.getIssuer("IssuerName");
console.log(certificateIssuer);

取得指定的憑證簽發者。

importCertificate(string, Uint8Array, ImportCertificateOptions)

將包含私密金鑰的現有有效憑證匯入 Azure 金鑰保存庫。 要匯入的憑證可以是 PFX 或 PEM 格式。 如果憑證是 PEM 格式,則 PEM 檔案必須包含金鑰以及 x509 憑證。 進行此作業需要憑證/匯入權限。

使用方式範例:

const client = new CertificateClient(url, credentials);
// See: @azure/keyvault-secrets
const certificateSecret = await secretClient.getSecret("MyCertificate");
const base64EncodedCertificate = certificateSecret.value!;
let buffer: Uint8Array;

if (isNode) {
  buffer = Buffer.from(base64EncodedCertificate, "base64");
} else {
  buffer = Uint8Array.from(atob(base64EncodedCertificate), (c) => c.charCodeAt(0));
}

await client.importCertificate("MyCertificate", buffer);

從憑證的秘密值匯入憑證

listDeletedCertificates(ListDeletedCertificatesOptions)

擷取目前保存庫中處於已刪除狀態且準備好復原或清除的憑證。 此作業包含刪除特定資訊。 這項作業需要憑證/取得/清單許可權。 此作業只能在啟用虛刪除的保存庫上啟用。

使用方式範例:

const client = new CertificateClient(url, credentials);
for await (const deletedCertificate of client.listDeletedCertificates()) {
  console.log(deletedCertificate);
}
for await (const page of client.listDeletedCertificates().byPage()) {
  for (const deletedCertificate of page) {
    console.log(deletedCertificate);
  }
}

列出已刪除的憑證

listPropertiesOfCertificates(ListPropertiesOfCertificatesOptions)

逐一查看保存庫中所有憑證的最新版本。 回應中會提供完整的憑證識別碼和屬性。 憑證不會傳回任何值。 此作業需要憑證/清單許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
// All in one call
for await (const certificateProperties of client.listPropertiesOfCertificates()) {
  console.log(certificateProperties);
}
// By pages
for await (const page of client.listPropertiesOfCertificates().byPage()) {
  for (const certificateProperties of page) {
    console.log(certificateProperties);
  }
}

列出指定之憑證的所有版本。

listPropertiesOfCertificateVersions(string, OperationOptions)

傳回指定之金鑰保存庫中憑證的版本。 這項作業需要憑證/清單許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
for await (const certificateProperties of client.listPropertiesOfCertificateVersions("MyCertificate")) {
  console.log(certificateProperties.version!);
}

列出憑證的版本。

listPropertiesOfIssuers(OperationOptions)

傳回指定之金鑰保存庫中的憑證簽發者資源集。 這項作業需要憑證/manageissuers/getissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Test");
// All in one call
for await (const issuerProperties of client.listPropertiesOfIssuers()) {
  console.log(issuerProperties);
}
// By pages
for await (const page of client.listPropertiesOfIssuers().byPage()) {
  for (const issuerProperties of page) {
    console.log(issuerProperties);
  }
}

列出憑證簽發者。

mergeCertificate(string, Uint8Array[], OperationOptions)

使用服務中目前可用的金鑰組,執行憑證或憑證鏈結的合併。 此作業須有憑證/建立權限。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Unknown",
  subject: "cn=MyCert"
});
const poller = await client.getCertificateOperation("MyCertificate");
const { csr } = poller.getOperationState().certificateOperation!;
const base64Csr = Buffer.from(csr!).toString("base64");
const wrappedCsr = ["-----BEGIN CERTIFICATE REQUEST-----", base64Csr, "-----END CERTIFICATE REQUEST-----"].join("\n");

const fs = require("fs");
fs.writeFileSync("test.csr", wrappedCsr);

// Certificate available locally made using:
//   openssl genrsa -out ca.key 2048
//   openssl req -new -x509 -key ca.key -out ca.crt
// You can read more about how to create a fake certificate authority here: https://gist.github.com/Soarez/9688998

const childProcess = require("child_process");
childProcess.execSync("openssl x509 -req -in test.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out test.crt");
const base64Crt = fs.readFileSync("test.crt").toString().split("\n").slice(1, -1).join("");

await client.mergeCertificate("MyCertificate", [Buffer.from(base64Crt)]);

將已簽署的憑證要求合併至擱置的憑證

purgeDeletedCertificate(string, OperationOptions)

執行無法復原的指定憑證刪除作業,而無法復原。 如果復原層級未指定「可清除」,則無法使用此作業。 此作業需要憑證/清除許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const deletePoller = await client.beginDeleteCertificate("MyCertificate");
await deletePoller.pollUntilDone();
// Deleting a certificate takes time, make sure to wait before purging it
client.purgeDeletedCertificate("MyCertificate");

取得已刪除的憑證

restoreCertificateBackup(Uint8Array, OperationOptions)

將備份的憑證及其所有版本還原至保存庫。 這項作業需要憑證/還原許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
const backup = await client.backupCertificate("MyCertificate");
const poller = await client.beginDeleteCertificate("MyCertificate");
await poller.pollUntilDone();
// Some time is required before we're able to restore the certificate
await client.restoreCertificateBackup(backup!);

從備份還原憑證

setContacts(CertificateContact[], OperationOptions)

設定金鑰保存庫的憑證連絡人。 這項作業需要憑證/managecontacts 許可權。

使用方式範例:

let client = new CertificateClient(url, credentials);
await client.setContacts([{
  email: "b@b.com",
  name: "b",
  phone: "222222222222"
}]);

設定憑證連絡人。

updateCertificatePolicy(string, CertificatePolicy, OperationOptions)

更新指定憑證的憑證原則。 這項作業需要憑證/更新許可權。 取得憑證的原則

updateCertificateProperties(string, string, UpdateCertificateOptions)

在指定的憑證上套用指定的更新;唯一更新的專案是憑證的屬性。 這項作業需要憑證/更新許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});

// You may pass an empty string for version which will update
// the latest version of the certificate
await client.updateCertificateProperties("MyCertificate", "", {
  tags: {
    customTag: "value"
  }
});

更新憑證

updateIssuer(string, UpdateIssuerOptions)

updateIssuer 作業會在指定的憑證簽發者實體上執行更新。 這項作業需要憑證/setissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Test");
await client.updateIssuer("IssuerName", {
  provider: "Provider2"
});

更新指定的憑證簽發者。

建構函式詳細資料

CertificateClient(string, TokenCredential, CertificateClientOptions)

建立 CertificateClient 的實例。

new CertificateClient(vaultUrl: string, credential: TokenCredential, clientOptions?: CertificateClientOptions)

參數

vaultUrl

string

保存庫的基底 URL。 您應該驗證此 URL 是否參考有效的金鑰保存庫資源。 如需詳細資訊,請參閱<https://aka.ms/azsdk/blog/vault-uri>。

credential
TokenCredential

物件,實作 TokenCredential 介面,用來驗證對服務的要求。 @azure/identity使用套件來建立符合您需求的認證。

clientOptions
CertificateClientOptions

用來設定金鑰保存庫 API 要求的管線選項。 省略此參數以使用預設管線組態。

屬性詳細資料

vaultUrl

保存庫的基底 URL

vaultUrl: string

屬性值

string

方法詳細資料

backupCertificate(string, OperationOptions)

要求將指定憑證的備份下載至用戶端。 將會下載所有版本的憑證。 這項作業需要憑證/備份許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
const backup = await client.backupCertificate("MyCertificate");

產生憑證的備份

function backupCertificate(certificateName: string, options?: OperationOptions): Promise<undefined | Uint8Array>

參數

certificateName

string

憑證的名稱

options
OperationOptions

選擇性參數

傳回

Promise<undefined | Uint8Array>

beginCreateCertificate(string, CertificatePolicy, BeginCreateCertificateOptions)

建立新的憑證。 如果這是第一個版本,則會建立憑證資源。 此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候,直到憑證完全復原為止。

注意: 傳送 Self 作為 issuerName 憑證原則的 將會建立自我簽署憑證。

此作業須有憑證/建立權限。

使用方式範例:

const client = new CertificateClient(url, credentials);
const certificatePolicy = {
  issuerName: "Self",
  subject: "cn=MyCert"
};
const createPoller = await client.beginCreateCertificate("MyCertificate", certificatePolicy);

// The pending certificate can be obtained by calling the following method:
const pendingCertificate = createPoller.getResult();

// Serializing the poller
const serialized = createPoller.toString();

// A new poller can be created with:
// const newPoller = await client.beginCreateCertificate("MyCertificate", certificatePolicy, { resumeFrom: serialized });

// Waiting until it's done
const certificate = await createPoller.pollUntilDone();
console.log(certificate);

建立憑證

function beginCreateCertificate(certificateName: string, policy: CertificatePolicy, options?: BeginCreateCertificateOptions): Promise<PollerLikeWithCancellation<CreateCertificateState, KeyVaultCertificateWithPolicy>>

參數

certificateName

string

憑證的名稱

options
BeginCreateCertificateOptions

選擇性參數

傳回

beginDeleteCertificate(string, CertificatePollerOptions)

DELETE 作業適用于儲存在 Azure 金鑰保存庫中的任何憑證。 DELETE 無法套用至個別版本的憑證。 此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候,直到憑證完全復原為止。

這項作業需要憑證/刪除許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const createPoller = await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
await createPoller.pollUntilDone();

const deletePoller = await client.beginDeleteCertificate("MyCertificate");

// Serializing the poller
const serialized = deletePoller.toString();

// A new poller can be created with:
// const newPoller = await client.beginDeleteCertificate("MyCertificate", { resumeFrom: serialized });

// Waiting until it's done
const deletedCertificate = await deletePoller.pollUntilDone();
console.log(deletedCertificate);

從指定的金鑰保存庫刪除憑證。

function beginDeleteCertificate(certificateName: string, options?: CertificatePollerOptions): Promise<PollerLike<DeleteCertificateState, DeletedCertificate>>

參數

certificateName

string

憑證的名稱。

options
CertificatePollerOptions

選擇性參數

傳回

beginRecoverDeletedCertificate(string, CertificatePollerOptions)

復原指定保存庫中已刪除的憑證。 此作業只能在已啟用虛刪除的保存庫上執行。 此作業 此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候憑證完全復原。

這項作業需要憑證/復原許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);

const deletePoller = await client.beginDeleteCertificate("MyCertificate");
await deletePoller.pollUntilDone();

const recoverPoller = await client.beginRecoverDeletedCertificate("MyCertificate");

// Serializing the poller
const serialized = deletePoller.toString();

// A new poller can be created with:
// const newPoller = await client.beginRecoverDeletedCertificate("MyCertificate", { resumeFrom: serialized });

// Waiting until it's done
const certificate = await recoverPoller.pollUntilDone();
console.log(certificate);

復原已刪除的憑證

function beginRecoverDeletedCertificate(certificateName: string, options?: CertificatePollerOptions): Promise<PollerLike<RecoverDeletedCertificateState, KeyVaultCertificateWithPolicy>>

參數

certificateName

string

已刪除憑證的名稱

options
CertificatePollerOptions

選擇性參數

傳回

createIssuer(string, string, CreateIssuerOptions)

createIssuer 作業會新增或更新指定的憑證簽發者。 這項作業需要憑證/setissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Test");

設定指定的憑證簽發者。

function createIssuer(issuerName: string, provider: string, options?: CreateIssuerOptions): Promise<CertificateIssuer>

參數

issuerName

string

簽發者的名稱。

provider

string

簽發者提供者。

options
CreateIssuerOptions

選擇性參數

傳回

deleteCertificateOperation(string, OperationOptions)

刪除所建立之指定憑證的建立作業。 不再建立憑證。 這項作業需要憑證/更新許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
await client.deleteCertificateOperation("MyCertificate");
await client.getCertificateOperation("MyCertificate"); // Throws error: Pending certificate not found: "MyCertificate"

刪除憑證的作業

function deleteCertificateOperation(certificateName: string, options?: OperationOptions): Promise<CertificateOperation>

參數

certificateName

string

憑證的名稱

options
OperationOptions

選擇性參數

傳回

deleteContacts(OperationOptions)

刪除所有憑證連絡人。 這項作業需要憑證/managecontacts 許可權。

使用方式範例:

let client = new CertificateClient(url, credentials);
await client.setContacts([{
  email: "b@b.com",
  name: "b",
  phone: "222222222222"
}]);
await client.deleteContacts();

刪除所有憑證連絡人

function deleteContacts(options?: OperationOptions): Promise<undefined | CertificateContact[]>

參數

options
OperationOptions

選擇性參數

傳回

Promise<undefined | CertificateContact[]>

deleteIssuer(string, OperationOptions)

deleteIssuer 作業會永久從保存庫移除指定的憑證簽發者。 這項作業需要憑證/manageissuers/deleteissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Provider");
await client.deleteIssuer("IssuerName");

刪除指定的憑證簽發者。

function deleteIssuer(issuerName: string, options?: OperationOptions): Promise<CertificateIssuer>

參數

issuerName

string

簽發者的名稱。

options
OperationOptions

選擇性參數

傳回

getCertificate(string, OperationOptions)

取得特定憑證中可用的最新資訊,包括憑證的原則。 這項作業需要憑證/取得許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const poller = await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
await poller.pollUntilDone();
const certificate = await client.getCertificate("MyCertificate");
console.log(certificate);

從憑證的名稱擷取憑證, (包含憑證原則)

function getCertificate(certificateName: string, options?: OperationOptions): Promise<KeyVaultCertificateWithPolicy>

參數

certificateName

string

憑證的名稱

options
OperationOptions

選擇性參數

傳回

getCertificateOperation(string, CertificatePollerOptions)

取得與指定憑證相關聯的建立作業。 這項作業需要憑證/取得許可權。 此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候,直到憑證完全復原為止。

使用方式範例:

const client = new CertificateClient(url, credentials);
const createPoller = await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});

const poller = await client.getCertificateOperation("MyCertificate");
const pendingCertificate = poller.getResult();

const certificateOperation = poller.getOperationState().certificateOperation;
console.log(certificateOperation);

取得憑證的輪詢器作業

function getCertificateOperation(certificateName: string, options?: CertificatePollerOptions): Promise<PollerLikeWithCancellation<CertificateOperationState, KeyVaultCertificateWithPolicy>>

參數

certificateName

string

憑證的名稱

options
CertificatePollerOptions

選擇性參數

傳回

getCertificatePolicy(string, OperationOptions)

getCertificatePolicy 作業會傳回指定金鑰保存庫中的指定憑證原則資源。 這項作業需要憑證/取得許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
const policy = await client.getCertificatePolicy("MyCertificate");
console.log(policy);

取得憑證的原則

function getCertificatePolicy(certificateName: string, options?: OperationOptions): Promise<CertificatePolicy>

參數

certificateName

string

憑證的名稱

options
OperationOptions

選擇性參數

傳回

getCertificateVersion(string, string, OperationOptions)

取得特定版本上特定憑證的相關資訊。 它不會傳回憑證的原則。 這項作業需要憑證/取得許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const poller = await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
await poller.pollUntilDone();
const certificateWithPolicy = await client.getCertificate("MyCertificate");
const certificate = await client.getCertificateVersion("MyCertificate", certificateWithPolicy.properties.version!);
console.log(certificate);

從憑證的名稱和指定的版本擷取憑證

function getCertificateVersion(certificateName: string, version: string, options?: OperationOptions): Promise<KeyVaultCertificate>

參數

certificateName

string

憑證的名稱

version

string

憑證的特定版本

options
OperationOptions

選擇性參數

傳回

getContacts(OperationOptions)

傳回指定之金鑰保存庫中的憑證連絡人資源集。 這項作業需要憑證/managecontacts 許可權。

使用方式範例:

let client = new CertificateClient(url, credentials);
await client.setContacts([{
  email: "b@b.com",
  name: "b",
  phone: "222222222222"
}]);
const contacts = await client.getContacts();
console.log(contacts);

設定憑證連絡人。

function getContacts(options?: OperationOptions): Promise<undefined | CertificateContact[]>

參數

options
OperationOptions

選擇性參數

傳回

Promise<undefined | CertificateContact[]>

getDeletedCertificate(string, OperationOptions)

擷取已刪除的憑證資訊及其屬性,例如保留間隔、排程的永久刪除和目前的刪除復原層級。 這項作業需要憑證/取得許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const deletedCertificate = await client.getDeletedCertificate("MyDeletedCertificate");
console.log("Deleted certificate:", deletedCertificate);

取得已刪除的憑證

function getDeletedCertificate(certificateName: string, options?: OperationOptions): Promise<DeletedCertificate>

參數

certificateName

string

憑證的名稱

options
OperationOptions

選擇性參數

傳回

getIssuer(string, OperationOptions)

getIssuer 作業會傳回指定金鑰保存庫中的指定憑證簽發者資源。 這項作業需要憑證/manageissuers/getissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Test");
const certificateIssuer = await client.getIssuer("IssuerName");
console.log(certificateIssuer);

取得指定的憑證簽發者。

function getIssuer(issuerName: string, options?: OperationOptions): Promise<CertificateIssuer>

參數

issuerName

string

簽發者的名稱。

options
OperationOptions

選擇性參數

傳回

importCertificate(string, Uint8Array, ImportCertificateOptions)

將包含私密金鑰的現有有效憑證匯入 Azure 金鑰保存庫。 要匯入的憑證可以是 PFX 或 PEM 格式。 如果憑證是 PEM 格式,則 PEM 檔案必須包含金鑰以及 x509 憑證。 進行此作業需要憑證/匯入權限。

使用方式範例:

const client = new CertificateClient(url, credentials);
// See: @azure/keyvault-secrets
const certificateSecret = await secretClient.getSecret("MyCertificate");
const base64EncodedCertificate = certificateSecret.value!;
let buffer: Uint8Array;

if (isNode) {
  buffer = Buffer.from(base64EncodedCertificate, "base64");
} else {
  buffer = Uint8Array.from(atob(base64EncodedCertificate), (c) => c.charCodeAt(0));
}

await client.importCertificate("MyCertificate", buffer);

從憑證的秘密值匯入憑證

function importCertificate(certificateName: string, certificateBytes: Uint8Array, options?: ImportCertificateOptions): Promise<KeyVaultCertificateWithPolicy>

參數

certificateName

string

憑證的名稱

certificateBytes

Uint8Array

包含 X.509 憑證和私密金鑰之憑證的 PFX 或 ASCII PEM 格式值

options
ImportCertificateOptions

選擇性參數

傳回

listDeletedCertificates(ListDeletedCertificatesOptions)

擷取目前保存庫中處於已刪除狀態且準備好復原或清除的憑證。 此作業包含刪除特定資訊。 這項作業需要憑證/取得/清單許可權。 此作業只能在啟用虛刪除的保存庫上啟用。

使用方式範例:

const client = new CertificateClient(url, credentials);
for await (const deletedCertificate of client.listDeletedCertificates()) {
  console.log(deletedCertificate);
}
for await (const page of client.listDeletedCertificates().byPage()) {
  for (const deletedCertificate of page) {
    console.log(deletedCertificate);
  }
}

列出已刪除的憑證

function listDeletedCertificates(options?: ListDeletedCertificatesOptions): PagedAsyncIterableIterator<DeletedCertificate, DeletedCertificate[], PageSettings>

參數

options
ListDeletedCertificatesOptions

選擇性參數

傳回

listPropertiesOfCertificates(ListPropertiesOfCertificatesOptions)

逐一查看保存庫中所有憑證的最新版本。 回應中會提供完整的憑證識別碼和屬性。 憑證不會傳回任何值。 此作業需要憑證/清單許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
// All in one call
for await (const certificateProperties of client.listPropertiesOfCertificates()) {
  console.log(certificateProperties);
}
// By pages
for await (const page of client.listPropertiesOfCertificates().byPage()) {
  for (const certificateProperties of page) {
    console.log(certificateProperties);
  }
}

列出指定之憑證的所有版本。

function listPropertiesOfCertificates(options?: ListPropertiesOfCertificatesOptions): PagedAsyncIterableIterator<CertificateProperties, CertificateProperties[], PageSettings>

參數

options
ListPropertiesOfCertificatesOptions

選擇性參數

傳回

listPropertiesOfCertificateVersions(string, OperationOptions)

傳回指定之金鑰保存庫中憑證的版本。 這項作業需要憑證/清單許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
for await (const certificateProperties of client.listPropertiesOfCertificateVersions("MyCertificate")) {
  console.log(certificateProperties.version!);
}

列出憑證的版本。

function listPropertiesOfCertificateVersions(certificateName: string, options?: OperationOptions): PagedAsyncIterableIterator<CertificateProperties, CertificateProperties[], PageSettings>

參數

certificateName

string

憑證的名稱。

options
OperationOptions

選擇性參數

傳回

listPropertiesOfIssuers(OperationOptions)

傳回指定之金鑰保存庫中的憑證簽發者資源集。 這項作業需要憑證/manageissuers/getissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Test");
// All in one call
for await (const issuerProperties of client.listPropertiesOfIssuers()) {
  console.log(issuerProperties);
}
// By pages
for await (const page of client.listPropertiesOfIssuers().byPage()) {
  for (const issuerProperties of page) {
    console.log(issuerProperties);
  }
}

列出憑證簽發者。

function listPropertiesOfIssuers(options?: OperationOptions): PagedAsyncIterableIterator<IssuerProperties, IssuerProperties[], PageSettings>

參數

options
OperationOptions

選擇性參數

傳回

mergeCertificate(string, Uint8Array[], OperationOptions)

使用服務中目前可用的金鑰組,執行憑證或憑證鏈結的合併。 此作業須有憑證/建立權限。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Unknown",
  subject: "cn=MyCert"
});
const poller = await client.getCertificateOperation("MyCertificate");
const { csr } = poller.getOperationState().certificateOperation!;
const base64Csr = Buffer.from(csr!).toString("base64");
const wrappedCsr = ["-----BEGIN CERTIFICATE REQUEST-----", base64Csr, "-----END CERTIFICATE REQUEST-----"].join("\n");

const fs = require("fs");
fs.writeFileSync("test.csr", wrappedCsr);

// Certificate available locally made using:
//   openssl genrsa -out ca.key 2048
//   openssl req -new -x509 -key ca.key -out ca.crt
// You can read more about how to create a fake certificate authority here: https://gist.github.com/Soarez/9688998

const childProcess = require("child_process");
childProcess.execSync("openssl x509 -req -in test.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out test.crt");
const base64Crt = fs.readFileSync("test.crt").toString().split("\n").slice(1, -1).join("");

await client.mergeCertificate("MyCertificate", [Buffer.from(base64Crt)]);

將已簽署的憑證要求合併至擱置的憑證

function mergeCertificate(certificateName: string, x509Certificates: Uint8Array[], options?: OperationOptions): Promise<KeyVaultCertificateWithPolicy>

參數

certificateName

string

憑證的名稱

x509Certificates

Uint8Array[]

要合併的憑證 ()

options
OperationOptions

選擇性參數

傳回

purgeDeletedCertificate(string, OperationOptions)

執行無法復原的指定憑證刪除作業,而無法復原。 如果復原層級未指定「可清除」,則無法使用此作業。 此作業需要憑證/清除許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
const deletePoller = await client.beginDeleteCertificate("MyCertificate");
await deletePoller.pollUntilDone();
// Deleting a certificate takes time, make sure to wait before purging it
client.purgeDeletedCertificate("MyCertificate");

取得已刪除的憑證

function purgeDeletedCertificate(certificateName: string, options?: OperationOptions): Promise<null>

參數

certificateName

string

要清除的已刪除憑證名稱

options
OperationOptions

選擇性參數

傳回

Promise<null>

restoreCertificateBackup(Uint8Array, OperationOptions)

將備份的憑證及其所有版本還原至保存庫。 這項作業需要憑證/還原許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});
const backup = await client.backupCertificate("MyCertificate");
const poller = await client.beginDeleteCertificate("MyCertificate");
await poller.pollUntilDone();
// Some time is required before we're able to restore the certificate
await client.restoreCertificateBackup(backup!);

從備份還原憑證

function restoreCertificateBackup(backup: Uint8Array, options?: OperationOptions): Promise<KeyVaultCertificateWithPolicy>

參數

backup

Uint8Array

要從中還原的備份憑證

options
OperationOptions

選擇性參數

傳回

setContacts(CertificateContact[], OperationOptions)

設定金鑰保存庫的憑證連絡人。 這項作業需要憑證/managecontacts 許可權。

使用方式範例:

let client = new CertificateClient(url, credentials);
await client.setContacts([{
  email: "b@b.com",
  name: "b",
  phone: "222222222222"
}]);

設定憑證連絡人。

function setContacts(contacts: CertificateContact[], options?: OperationOptions): Promise<undefined | CertificateContact[]>

參數

contacts

CertificateContact[]

要使用的連絡人

options
OperationOptions

選擇性參數

傳回

Promise<undefined | CertificateContact[]>

updateCertificatePolicy(string, CertificatePolicy, OperationOptions)

更新指定憑證的憑證原則。 這項作業需要憑證/更新許可權。 取得憑證的原則

function updateCertificatePolicy(certificateName: string, policy: CertificatePolicy, options?: OperationOptions): Promise<CertificatePolicy>

參數

certificateName

string

憑證的名稱

policy
CertificatePolicy

憑證原則

options
OperationOptions

選擇性參數

傳回

updateCertificateProperties(string, string, UpdateCertificateOptions)

在指定的憑證上套用指定的更新;唯一更新的專案是憑證的屬性。 這項作業需要憑證/更新許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.beginCreateCertificate("MyCertificate", {
  issuerName: "Self",
  subject: "cn=MyCert"
});

// You may pass an empty string for version which will update
// the latest version of the certificate
await client.updateCertificateProperties("MyCertificate", "", {
  tags: {
    customTag: "value"
  }
});

更新憑證

function updateCertificateProperties(certificateName: string, version: string, options?: UpdateCertificateOptions): Promise<KeyVaultCertificate>

參數

certificateName

string

憑證的名稱

version

string

要更新 (空字串的憑證版本將會更新最新版本)

options
UpdateCertificateOptions

選項,包括要更新的內容

傳回

updateIssuer(string, UpdateIssuerOptions)

updateIssuer 作業會在指定的憑證簽發者實體上執行更新。 這項作業需要憑證/setissuers 許可權。

使用方式範例:

const client = new CertificateClient(url, credentials);
await client.createIssuer("IssuerName", "Test");
await client.updateIssuer("IssuerName", {
  provider: "Provider2"
});

更新指定的憑證簽發者。

function updateIssuer(issuerName: string, options?: UpdateIssuerOptions): Promise<CertificateIssuer>

參數

issuerName

string

簽發者的名稱。

options
UpdateIssuerOptions

選擇性參數

傳回