Skip to content

Import-AzKeyVaultCertificate yields Cannot find the requested object #18494

Closed
@cveld

Description

Description

When running the cmdlet Import-AzKeyVaultCertificate it yields the error Cannot find the requested object.

import-azkeyvaultcertificate -VaultName myvault -name examplecert -FilePath C:\temp\cert\examplecert.pem

I expect the certificate to be imported.

Interestingly when running the az cli counterpart, this runs fine:

az keyvault certificate import --vault-name myvault -n examplecert -f C:\temp\cert\examplecert.pem

Contents of examplecert.pem:

-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCeUmity0so5Kyv
mXtVkeg0IXclvN2StX7IJEx8OJmGmNCRV4gi89i/0RCWtYaEsX/XbYwzel0mqgor
LezaOVs77N6pupyOA+I02ZBYTkpIvDcbzDr/JreEzo/4pEzkGxV4VQD3lfwHsX2K
P1dLPB0E8ZFYZnmHJdKQbyWLJijQt2razCp5h5x0OHhngdMSryxJ/dOvQ3SveSfO
ohXH6xZ3lpRNAx3jLWTmZp4+mGlcz1qpCyxVmWI+a5J6tKy3qMZi0S+ymb5nbS1s
T0mvhaSwLvtNvNyRXTDPVmnR9sbJn2oM/dc4UHGQGMwyGyk5JdgCI47aGZh2wYj9
Z4as1SyBAgMBAAECggEAXIksN9BnyKoHqMcbiEM0piudOUhvdU1xocddkQl/6mSt
GxY/Mra1zD+E46GL00jvwNl9paTyhyPBt8Uq982oXpku96Nj17m7YEp9jK+NyX+A
8lVncjSN9SjKi3h0nKqb3O5KF2vpmBGMn94vxoCHMZmD61hR1cUsklD0b6VJG9v9
T97S32Cac2HHC4oTFln9nVc8Ajufj57Fjq2pXUHQtuRVXdKYn1zjgVc4jjOf366P
Fzgk87OC4wd3HetDAj+QAIul1xU7sAAxlkaE9vbXUXY6sQpEFkhyZKvONHr5asHW
dPQ08l57NPl5mYaF+K1DTvk5jL8Qy1jMZIsWW9YohQKBgQDMwRaFaOyXK+/18vo6
loz2vaP5fQqvYrKFJnXch4MEETaMCYaSfnU6xyFmzIHv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AwggEKAoIBAQCeUmity0so5KyvmXtVkeg0IXclvN2StX7IJEx8OJmG
mNCRV4gi89i/0RCWtYaEsX/XbYwzel0mqgorLezaOVs77N6pupyOA+I02ZBYTkpI
vDcbzDr/JreEzo/4pEzkGxV4VQD3lfwHsX2KP1dLPB0E8ZFYZnmHJdKQbyWLJijQ
t2razCp5h5x0OHhngdMSryxJ/dOvQ3SveSfOohXH6xZ3lpRNAx3jLWTmZp4+mGlc
z1qpCyxVmWI+a5J6tKy3qMZi0S+ymb5nbS1sT0mvhaSwLvtNvNyRXTDPVmnR9sbJ
n2oM/dc4UHGQGMwyGyk5JdgCI47aGZh2wYj9Z4as1SyBAgMBAAGjYzBhMB0GA1Ud
DgQWBBTMTnCgx7pdjOPjw3bNsh7fR3vnDDAfBgNVHSMEGDAWgBTMTnCgx7pdjOPj
w3bNsh7fR3vnDDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjANBgkq
hkiG9w0BAQsFAAOCAQEAcjrinpLRKTsW+6rY60qycHunRE/GcGVyEkVV5cE1vsc2
ZmLonfNJ3Ixky618hwp9bC38TicXHmwPAQdlbSJTaf/jAE7t7lWqxjnFKbyVR2bt
vxKxl/sKtI50u2jlv6babqdWUR6qo5Hup5zhO8u5MV4wlsY6h5DDNwIN9jHcNswU
1B/c6OFo0aKB3YCr+TPvRcaxSrzE/PpFeS0mU+vgsVrUWXTKSe+PH0hMvkgWek6Y
YLHEo0nZrjEQ8zPRL+R1G12hb2Y4GVo2rIAYV1Rm9mwGOdkQqVNI5+zzO84QILvw
jEUXFu+BAH/TJagf11MMwBrCKDr7T7VIXwL9zvGbLQ==
-----END CERTIFICATE-----

Issue script & Debug output

DEBUG: 10:25:05 PM - ImportAzureKeyVaultCertificate begin processing with ParameterSet 'ImportCertificateFromFile'.
DEBUG: 10:25:05 PM - using account id '<redacted>'...
Import-AzKeyVaultCertificate: Cannot find the requested object.

Environment data

$psversiontable

Name                           Value
----                           -----
PSVersion                      7.2.4
PSEdition                      Core
GitCommitId                    7.2.4
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

Script     4.4.0                 Az.KeyVault

Error output

HistoryId: 57

�[32;1mMessage        : �[0mCannot find the requested object.
�[32;1mStackTrace     : �[0m   at Internal.Cryptography.Pal.StorePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
�[32;1m                 �[0m   at System.Security.Cryptography.X509Certificates.X509Certificate2Collection.Import(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
�[32;1m                 �[0m   at Microsoft.Azure.Commands.KeyVault.ImportAzureKeyVaultCertificate.InitializeCertificateCollection()
�[32;1m                 �[0m   at Microsoft.Azure.Commands.KeyVault.ImportAzureKeyVaultCertificate.ExecuteCmdlet()
�[32;1m                 �[0m   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
�[32;1m                 �[0m   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
�[32;1m                 �[0m   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
�[32;1m                 �[0m   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
�[32;1mException      : �[0mInternal.Cryptography.CryptoThrowHelper+WindowsCryptographicException
�[32;1mInvocationInfo : �[0m{Import-AzKeyVaultCertificate}
�[32;1mLine           : �[0mimport-azkeyvaultcertificate -VaultName myvault -name examplecert -FilePath C:\temp\cert\examplecert.pem
�[32;1mPosition       : �[0mAt line:1 char:1
�[32;1m                 �[0m+ import-azkeyvaultcertificate -VaultName myvault -name examplecert - …
�[32;1m                 �[0m+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[32;1mHistoryId      : �[0m57

(what is the best way to suppress these TTY commands?)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

KeyVaultbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reported

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions