An Azure service for virtual machines (VMs) that helps address organizational security and compliance requirements by encrypting the VM boot and data disks with keys and policies that are controlled in Azure Key Vault.
The error you're encountering is 0xc142506f RUNTIME_E_KEYVAULT_SECRET_WRAP_WITH_KEK_FAILED - a well-documented issue specifically affecting Windows Server 2022 and Windows 11 systems.
The primary cause is that your Key Encryption Key (KEK) uses an RSA 2048-bit key size, which is no longer supported for these newer operating systems
We have reference documentation https://learn.microsoft.com/en-us/azure/virtual-machines/windows/disk-encryption-overview
Windows Server 2022 and Windows 11 include a newer version of BitLocker and currently doesn't work with RSA 2048-bit Key Encryption Keys.
Until resolved, use an RSA 3072 or RSA 4096-bit keys, as described in https://learn.microsoft.com/en-us/azure/virtual-machines/windows/disk-encryption-overview#supported-operating-systems
Connect to your Key Vault and check the current KEK
$KeyVaultName = "YourKeyVaultName"
$KEKName = "YourKEKName"
Get key details
$KEK = Get-AzKeyVaultKey -VaultName $KeyVaultName -Name $KEKName
$KEK.Attributes
Please confirm whether key vault is in the same region and subscription as your VM.
Check VM location
$VM = Get-AzVM -ResourceGroupName "YourResourceGroup" -Name "YourVMName"
$VM.Location
Check Key Vault location
$KeyVault = Get-AzKeyVault -VaultName $KeyVaultName
$KeyVault.Location
For creation of new RSA 3072 or 4096-bit KEK
az keyvault key create --name "myKEK" --vault-name "<your-unique-keyvault-name>" --kty RSA --size 4096
reference documentation: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/disk-encryption-key-vault?tabs=azure-portal
Enable Key Vault for disk encryption
Set-AzKeyVaultAccessPolicy -VaultName $KeyVaultName -EnabledForDiskEncryption
Enable for deployment (Note: if needed)
Set-AzKeyVaultAccessPolicy -VaultName $KeyVaultName -EnabledForDeployment
Enable for template deployment (Note: if needed)
Set-AzKeyVaultAccessPolicy -VaultName $KeyVaultName -EnabledForTemplateDeployment
This example assumes that you are using the same key vault for both the disk encryption key and the KEK :
$KeyVault = Get-AzKeyVault -VaultName "<your-unique-keyvault-name>" -ResourceGroupName "myResourceGroup"
$KEK = Get-AzKeyVaultKey -VaultName "<your-unique-keyvault-name>" -Name "myKEK"
Set-AzVMDiskEncryptionExtension -ResourceGroupName MyResourceGroup -VMName "MyVM" -DiskEncryptionKeyVaultUrl $KeyVault.VaultUri -DiskEncryptionKeyVaultId $KeyVault.ResourceId -KeyEncryptionKeyVaultId $KeyVault.ResourceId -KeyEncryptionKeyUrl $KEK.Id -SkipVmBackup -VolumeType All
Kindly let us know if the suggested steps helps or you need further assistance on this issue
Regards
Himanshu