Crée un certificat exportable auto-signé dans le magasin personnel de l'utilisateur courant pour un usage de signature numérique.
$certname = "CertForVpn" $cert= New-SelfSignedCertificate -Subject "CN=$certname" -CertStoreLocation "Cert:\CurrentUser\My" -KeyExportPolicy Exportable -KeySpec Signature -KeyLength 2048 -KeyAlgorithm RSA -HashAlgorithm SHA256 Export-Certificate -Cert $cert -FilePath "C:\temp\$certname.cer"
Le script ci-dessous créé 2 certificats : un root ca et un client, utilisé pour configurer une authentification par certificat, par exemple dans une connexion VPN point-à-site (P2S)
$certnameca = "RootCa"
$certnamecl = "ClientP2S"
$cert = New-SelfSignedCertificate -Type Custom -KeySpec Signature -Subject "CN=$certnameca" -KeyExportPolicy Exportable -HashAlgorithm sha256 -KeyLength 2048 -CertStoreLocation "Cert:\CurrentUser\My" -KeyUsageProperty Sign -KeyUsage CertSign
New-SelfSignedCertificate -Type Custom -DnsName $certnamecl -KeySpec Signature -Subject "CN=$certnamecl" -KeyExportPolicy Exportable -HashAlgorithm sha256 -KeyLength 2048 -CertStoreLocation "Cert:\CurrentUser\My" -Signer $cert -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2")
$DERCert = "C:\temp\$certnameca.cer"
$Base64Cert = "C:\temp\Base64_$certnameca.cer"
Export-Certificate -Cert $cert -FilePath $DERCert
Start-Process -FilePath 'certutil.exe' -ArgumentList "-encode $DERCert $Base64Cert" -WindowStyle Hidden