次の方法で共有


JavaScript を使用して Azure Key Vault でキーをバックアップ、削除、復元する

適切なプログラムの認証資格情報KeyClient を作成し、次に CryptographyClient を作成します。このクライアントを使用して Azure Key Vault のキーを設定、更新、およびローテーションします。

キーのバックアップ、削除、消去、復元

キーとそのバージョンを削除する前に、キーをバックアップし、セキュリティで保護されたデータ ストアにシリアル化します。 キーがバックアップされたら、キーとすべてのバージョンを削除します。 コンテナーで論理的な削除が使用されている場合は、消去日がキーを手動で渡すか消去するまで待機できます。 キーが消去されたら、バックアップからキーとすべてのバージョンを復元できます。 消去の前にキーを復元する場合は、バックアップ オブジェクトを使用する必要はありませんが、代わりに論理的に削除されたキーとすべてのバージョンを回復できます。

// Authenticate to Azure Key Vault
const credential = new DefaultAzureCredential();
const client = new KeyClient(
    `https://${process.env.AZURE_KEYVAULT_NAME}.vault.azure.net`,
    credential
);

// Create key
const keyName = `myKey-${Date.now()}`;
const key = await client.createRsaKey(keyName);
console.log(`${key.name} is created`);

// Backup key and all versions (as Uint8Array)
const keyBackup = await client.backupKey(keyName);
console.log(`${key.name} is backed up`);

// Delete key - wait until delete is complete
await (await client.beginDeleteKey(keyName)).pollUntilDone();
console.log(`${key.name} is deleted`);

// Purge soft-deleted key 
await client.purgeDeletedKey(keyName);
console.log(`Soft-deleted key, ${key.name}, is purged`);

if (keyBackup) {
    // Restore key and all versions to
    // Get last version
    const { name, key, properties } = await client.restoreKeyBackup(keyBackup);
    console.log(`${name} is restored from backup, latest version is ${properties.version}`);
    
    // do something with key
}

次のステップ