Hi Glyn, thanks for the quick response.
I am wondering if I have to add some extra Add-Type
Here is my code and the response:
$tenantAPIKey = 'dz52iegnlWe9Mgd1r4xnbYMW9gmzzkWVduUP5abNvqg='
$Certificate = Get-ChildItem -Path Cert:\LocalMachine\my | Where-Object Subject -eq 'CN=12063:RESTAPI4EUD'
[uri]$Url = 'https://mdm.airfrance.fr/api/mdm/dep/profiles/search?PageSize=40000'
Add-Type -AssemblyName System.Security
$bytes = [System.Text.Encoding]::UTF8.GetBytes(($Url.AbsolutePath))
$MemStream = New-Object -TypeName System.Security.Cryptography.Pkcs.ContentInfo -ArgumentList (,$bytes) -ErrorAction Stop
$SignedCMS = New-Object -TypeName System.Security.Cryptography.Pkcs.SignedCms -ArgumentList $MemStream,$true -ErrorAction Stop
$CMSigner = New-Object -TypeName System.Security.Cryptography.Pkcs.CmsSigner -ArgumentList $Certificate -Property @{IncludeOption = [System.Security.Cryptography.X509Certificates.X509IncludeOption]::EndCertOnly} -ErrorAction Stop
$null = $CMSigner.SignedAttributes.Add((New-Object -TypeName System.Security.Cryptography.Pkcs.Pkcs9SigningTime))
$SignedCMS.ComputeSignature($CMSigner)
$CMSHeader = '{0}{1}{2}' -f 'CMSURL','`1 ',$([System.Convert]::ToBase64String(($SignedCMS.Encode())))
Write-Output -InputObject $CMSHeader
Response 1:
CMSURL`1
Response 2:
Exception calling "ComputeSignature" with "1" argument(s): "Keyset does not exist
"
At C:\MDM\Omnissa.ps1:11 char:1
+ $SignedCMS.ComputeSignature($CMSigner)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CryptographicException
Exception calling "Encode" with "0" argument(s): "The CMS message is not signed."
At C:\MDM\Omnissa.ps1:12 char:46
+ ... URL','`1 ',$([System.Convert]::ToBase64String(($SignedCMS.Encode())))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException
Thanks in advance