Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void EnumerateKeyContainers()
- {
- string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string programDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
- //string userStore = Path.Combine(appDataPath,"Microsoft\\Crypto\\RSA");
- string machineStore = Path.Combine(programDataPath,"Application Data\\Microsoft\\Crypto\\RSA\\MachineKeys");
- string[] files = Directory.GetFiles(machineStore);
- foreach (var file in files)
- {
- try
- {
- byte[] container = File.ReadAllBytes(file);
- string containerName = Encoding.UTF8.GetString(container, 40, container[8] - 1);
- CspParameters cspp = new CspParameters();
- cspp.KeyContainerName = containerName;
- cspp.Flags |= CspProviderFlags.UseMachineKeyStore;
- RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspp);
- rsa.PersistKeyInCsp = true;
- string outputFileName = containerName + ".txt";
- using(StreamWriter streamWriter = new StreamWriter(Path.GetFullPath(outputFileName),false))
- {
- streamWriter.Write(rsa.ToXmlString(!rsa.PublicOnly));
- streamWriter.Flush();
- }
- rsa.Clear();
- }
- catch { }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement