Invoke-AzKeyVaultKeyOperation uses ASCII encoding to get bytes for string and Default encoding for the inverse #21269
Labels
Azure PS Team
bug
This issue requires a change to an existing behavior in the product in order to be resolved.
KeyVault
Tracking
We will track status and follow internally
Description
The Invoke-AzKeyVaultKeyOperation accepts a SecureString as input. For encrypt/wrap operations, the operation uses Encoding.ASCII.GetBytes() to convert the input to a byte[] for encryption. This results in data loss for any string that cannot be represented in the ASCII encoding. For compatibility, I'd recommend the UTF8 encoding instead.
Similarly, on decrypt/unwrap, PSKeyOperationResult uses System.Text.Encoding.Default which will vary based on platform. On .NET Core it'll be UTF8, but on .NET Framework it may be an ANSI code page. The same encoding needs to be used in both places to ensure that the original string is returned.
Issue script & Debug output
Environment data
Module versions
Error output
No response
The text was updated successfully, but these errors were encountered: