Aquí es un script de PowerShell que usamos para probar para un nombre de contenedor determinado:
# Test if an rsa key container exists on this system.
function Test-RsaKeyContainerName(
[Parameter(Mandatory=$true)][string] $ContainerName,
[Parameter(Mandatory=$false)][switch] $UserContainer = $false
) {
$csp = New-Object -TypeName "System.Security.Cryptography.CspParameters";
$csp.KeyContainerName = $ContainerName;
if (!($UserContainer)) {
$csp.Flags = [System.Security.Cryptography.CspProviderFlags]::UseMachineKeyStore;
}
$csp.Flags = $csp.Flags -bor [System.Security.Cryptography.CspProviderFlags]::UseExistingKey;
try {
$rsa = New-Object -TypeName "System.Security.Cryptography.RSACryptoServiceProvider" -ArgumentList ($csp);
} catch [System.Management.Automation.MethodInvocationException] {
if ($error[0].Exception.InnerException -ne $null -and
$error[0].Exception.InnerException.GetType() -eq [System.Security.Cryptography.CryptographicException] -and
$error[0].Exception.InnerException.Message.StartsWith("Keyset does not exist")) {
return $false;
} else {
throw;
}
}
return $true;
}
Si realmente se necesita para enumerar las claves instaladas en el sistema, que puede pedir prestado el código de keypal en http://www.jensign.com/KeyPal/index.html
No es una buena idea, si existía la llave antes de que el proceso se inició sería eliminado. –