Choose CSP when using Get-Certificate powershell

Georg2G 6 Reputation points
2020-10-06T12:26:47.407+00:00

Hi,

I am looking for a way to change the CSP which is being used by the Get-Certificate powershell function. To be precise, i am trying to use the CSP Type 24 Microsoft Enhanced RSA and AES Cryptographic Provider.

Issuing certificates from the ADCS Enterprise CA using the Get-Certificate command seems only possible when allowing CSP Type 1 (Microsoft Strong Cryptographic Provider Type: 1 - PROV_RSA_FULL) on the certificate template. Whenever i try to issue a certificate from a template which does not allow CSP Type 1, i get the error:

Command:

$certificate = Get-Certificate -Template $template `  
        -SubjectName "CN=$CommonName,O=$Organization,L=$Localization,S=$State,C=$Country,OU=$Department,E=$Email" `  
        -DnsName $SAN `  
        -CertStoreLocation "cert:\LocalMachine\My" `  
        -Url $uri  

Error:

Get-Certificate : CertEnroll::CX509Enrollment::Enroll: A certificate request could not be created. A certificate could not be issued by the certification authority.: Unknown cryptographic algorithm.   
0x80091002 (-2146889726 CRYPT_E_UNKNOWN_ALGO)  
At line:1 char:24  
+         $certificate = Get-Certificate -Template $template `  
+                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    + CategoryInfo          : NotSpecified: (:) [Get-Certificate], Exception  
    + FullyQualifiedErrorId : System.Exception,Microsoft.CertificateServices.Commands.GetCertificateCommand  

I checked on the official documentation site on MS for [get-certificate (https://learn.microsoft.com/en-us/powershell/module/pkiclient/get-certificate?view=win10-ps), but i could not find an option to define the CSP. There is no parameter to define the CSP.

I am able to issue CSP Type 24 certificates using certutil just fine.
I verified that the CA supports the CSP Type 24

certutil -csplist  
Provider Name: Microsoft Enhanced RSA and AES Cryptographic Provider  
Provider Type: 24 - PROV_RSA_AES  

I also check on the Windows Server 2019, where i am running the Get-Certificate that the CSP is supported by the OS:

Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Cryptography\Defaults\Provider  
  
    Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider  
  
Name                           Property                                                                                                                                                                    
----                           --------                                                                                                                                                                                                                                                                                                                                  
Microsoft Enhanced RSA and     Image Path : %SystemRoot%\system32\rsaenh.dll                                                                                                                               
AES Cryptographic Provider     SigInFile  : 0                                                                                                                                                              
                               Type       : 24     


Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Cryptography\Defaults\Provider Types'  
  
    Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Defaults\Provider Types  
  
  
Name                           Property                                                                                                                                                                    
----                           --------                                                                                                                                                                                                                                                                                                          
Type 024                       Name     : Microsoft Enhanced RSA and AES Cryptographic Provider                                                                                                            
                               TypeName : RSA Full and AES   

cheers,
Georg

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,851 questions
Windows Server Security
Windows Server Security
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Security: The precautions taken to guard against crime, attack, sabotage, espionage, or another threat.
1,720 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vadims Podāns 8,866 Reputation points MVP
    2020-10-06T13:47:58.097+00:00

    You cannot choose a CSP with Get-Certificate cmdlet. Instead, you have to change the CSP to use in certificate template, in Cryptography tab. It is the only correct and supported way.

    0 comments No comments