These keys are stored in the locations listed at the bottom of this post. Many network administrators aren't aware of the purpose of these files, and some forum posts on the web incorrectly advise people to delete these files. Of course, the impact of such an action is implementation/application specific. I was not able to read the files using the following code (perhaps some change is needed)
var files = System.IO.Directory.GetFiles(@"C:\ProgramData\Application Data\Microsoft\Crypto\RSA\MachineKeys\");
foreach (var f in files)
{
RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider();
var readFile = File.OpenRead( f.ToString());
byte[] FileOut = new byte[readFile.Length];
readFile.Read( FileOut, 0, (int)readFile.Length-1);
rsaKey.ImportCspBlob(FileOut);
}
It appears that the tool "User State Migration tool" is required to move this data from one computer to another. In addition some tool will need to expose the keys from CryptoAPI to the CNG after such a move.
I am not aware of any way to view the related files containerName
referenced in the CSP.
The Microsoft legacy CryptoAPI CSPs
store private keys in the following
directories.
User private
%APPDATA%\Microsoft\Crypto\RSA\User SID\
%APPDATA%\Microsoft\Crypto\DSS\User SID\
Local system private
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA\S-1-5-18\
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\DSS\S-1-5-18\
Local service private
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA\S-1-5-19\
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\DSS\S-1-5-19\
Network service private
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA\S-1-5-20\
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\DSS\S-1-5-20\
Shared private
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA\MachineKeys
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\DSS\MachineKeys
CNG stores private keys in the
following directories.
User private
%APPDATA%\Microsoft\Crypto\Keys
Local system private
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\SystemKeys
Local service private
%WINDIR%\ServiceProfiles\LocalService
Network service private
%WINDIR%\ServiceProfiles\NetworkService
Shared private
%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\Keys
Reference:
http://msdn.microsoft.com/en-us/library/bb204778(v=vs.85).aspx
LDAP
These keys are also stored in LDAP if credential roaming is enabled
ldifde.exe -s %LOGONSERVER% -f cscverify.ldf -r "(cn=USERNAME)" -l msPKIAccountCredentials,msPKIRoamingTimeStamp,msPKIDPAPIMasterKeys
Replace the word USERNAME in this command with the user name where credential roaming does not work. To ensure that Active Directory replication was already performed, use the -s option in the command and replace %LOGONSERVER% with the server the user actually logs on to. Make sure that the cscverify.ldf file shows values for the exported attributes.
The size of the LDAP entries is controled by DIMSRoarmingMaxNumTokens and DIMSRoamingMaxTokenSize registry keys (source)