Thanks Durga tried above and also one different method it worked. Thanks for your help.
Azure Devops - Issue while Extracting the Secret Value of the Key-Vault
I am getting the below Issue the Secret of the Key-Vault is coming as *** but after Base64 encoding it shows correct encoded-value.
But in Azure Devops PowerShell was facing issue while decoding the Encoded Base64 Key-Vault value.
- Then in PowerShell Script, to extract the Key-Vault values with the below command
$keyVaultValue = (Get-AzKeyVaultSecret -VaultName "xxx" -Name "DBPass")
Write-Host "Value of Value": $keyVaultValue
---- Output
Value of keyVaultValue : ***
After Encoding in Base64 for the above value of (keyVaultValue) getting the correct encoded-value. Checked in the base64 decode website (https://www.base64decode.org/) by encoded-value to check the decoded-value. ( Decoded-value is correct)
Encoded-Value
$encodedSecret = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($keyVaultValue))
Write-Host "Value of encodedSecret" $encodedSecret
---Output - for-example
Value of encodedSecret - xyz
Decoded-value
$decodedvalue = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('xyz'))
Write-Host "Value of DecodedSecret" $decodedvalue
---- Output
Value of decodedvalue : ***
Azure DevOps
6 answers
Sort by: Newest
-
Durga Reshma Malthi 11,375 Reputation points Microsoft External Staff Moderator
2025-06-03T08:23:19.8933333+00:00 Hi Hitesh N
To process all secrets retrieved from Azure Key Vault in a loop - encoding and decoding each one - you can use a foreach loop in PowerShell.
# Retrieve all secrets from the Key Vault $secrets = Get-AzKeyVaultSecret -VaultName "xxxx" # Loop through each secret, encode and decode the values foreach ($secret in $secrets) { $secretName = $secret.Name $secretValue = Get-AzKeyVaultSecret -VaultName "xxxx" -Name $secretName -AsPlainText Write-Host "Original Value for $secretName: $secretValue" # Encoding $encodedSecret = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($secretValue)) Write-Host "Encoded Value for $secretName: $encodedSecret" # Decoding $decodedValue = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($encodedSecret)) Write-Host "Decoded Value for $secretName: $decodedValue" }Hope this helps!
Please Let me know if you have any queries.
If you found the information helpful, please click "Upvote" on the post to let us know and consider accepting the answer as the token of appreciation. Thank You.
-
Hitesh N 20 Reputation points
2025-06-02T17:49:09.56+00:00 Thanks Durga for your response, followed the above steps after getting the KeyVaultSecret was getting the values as ***. After encoding and decoding the secret and passing the decoded values worked.
Had Question, how to retreive all the secrets from the KeyVault and pass it through the encoding and decoding in loop.
After the below command , was getting the output as below, how to fetch all the values of secret after the | ( which is ***), currently there are 3 secrets and how to pass it to $encodedSecret and $decodedvalue in foreach loop.
For-each *** value --> to Encode and Decode it.
$keyVaultValue = Get-AzKeyVaultSecret -VaultName "xxxx"
$keyVaultValue | % {Write-Output "$($.name) | $(Get-AzKeyVaultSecret -VaultName $.VaultName -Name $_.Name -AsPlainText)"}
Write-Host "Value of keyVaultValueSecret ": $keyVaultValueSecret
Value of keyVaultValueSecret :
DBUser | ***
DBPass | ***
DBPort | ***
#EncodedSecret
$encodedSecret = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($keyVaultValue))
#$encodedSecret = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($secret))
Write-Host "Value of encodedSecret" $encodedSecret
#DecodedSecret
$decodedvalue = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($encodedSecret))
Write-Host "Value of DecodedSecret" $decodedvalue
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
1 deleted comment
Comments have been turned off. Learn more
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more