Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Dear All,

I have created key which can we change once in a month, Now I want to store own 64 bit key in microsoft key container. So please help me out for the same.

If we use CspParameters class it automatic generate key and store in given container which name of container provide by the users then how to get actual key from container to encryption.

Actually we are using login authentication with symmetric key cryptography.

Please help us , We already spend more then a week over the same Task.

Thank in advanced!
Posted
Updated 24-Sep-14 21:46pm
v2

1 solution

Why would you want to do that? It seems awkward like you're trying to force your own will on Microsoft's tools etc. Here's why you really shouldn't do what you're asking. If you look at the Microsoft key container it looks like.


XML
<rsakeyvalue>  <modulus>uec452qwyOCbMW4ZSCNGGotjT14N54RqxsxGO9w4oVANyoeV87H9HfyjQTZGvDRAp2BOWnDHhvHfv37MHzhBvr8YkP9RNrsipHVvfp2zpLaSTU5upEz3KFZVbPL9WNiGPC7apuD+5Ic63KQlt/PCEb12KQO4BiIxzFjEkAeBXPE=
</modulus>
<exponent>AQAB</exponent>
<p>/MJX1FKEMl3JXJ7ZudNJOZEFwbgXQ6MOgSIgEwyBSU6FBni8TABKNIXLXvBGV3wO2WgmSlnpVYywbalKmldQ==
</p>
<q>vEluYi8BqLPKIavcKPeyO3ScVYCDiljGYQPG7U80l6dtftMCP28+Sp+p+1fy86ZgIECQTDJsLMm9G8rulDdeDQ==</q>
<dp>B3lvw3WVNzAjTNYv1AEvBNJSXSP06ouNlgGgT7rxF7ncF9AUJ/G1dxGPYebw9OEUuQ3Nj5mOVDwyXf6b5B2IKQ==</dp>
<dq>kl63S+Zk8MPLd7+FZ+eei6/MNH+yQmNe3F42T5cKOHa0nSnmDnApSZOzbaviN1z4TzpBsqpkA7FUrH1mWJxuJQ==</dq>
<inverseq>SgbeDWewNx8pyk4hH4QlvvXkayO6UWx1ODlxkAG1GXnrFF7E/8L7epmK5C0jdP3k0eIg3grfX0JMqgZR0DdoyA==</inverseq>
<d>Ui9rk7syDoxlb7PZz29wtZl7vQG6qeh7gAmc3yfbjU0j266XV1YPrasbzV+eY+PB1X0ZBpinTPwvS6xVt1OalGNRUnD2iJ51VnAKhnZx1OpJtIQmROzhar7UN8HY7EsFHzLUKHW9wu/9T330Yy8mG7RjzT4JpJuhqfC0QMD5KLE=</d>
</rsakeyvalue>


So essentially you want you're asking is for you to be able to put your own key in there and have Microsoft calculate out all these values which, in theory the algorithms probably could. However then you run the risk of not having a key which is cryptographically strong enough.

What's the real ask here? I can't think of a reason why the keys' that Microsoft gives you wouldn't be strong enough. If you really are intent on using your own keys then you should be creating your own keys and "storing" them securely, database, ACL'd file list etc. Which is really all the protection the Microsoft Key container gives you. The Microsoft key container really doesn't give you an enhanced level of protection out of the box that you couldn't do yourself. If you're intent on using your own keys, then perhaps you should be doing it yourself. If you're only requirement is to change your keys monthly there are other solutions.
 
Share this answer
 
Comments
Bhanu Pratap Verma 7-Nov-14 6:17am    
Dear All,

I am using the key container for encrypt and decrypt for the password.

I am using the csp class and RSACryptoServiceProvider class to manage the container and key.
My application is running perfectly when I am running in my visual studio 2010.

When I hosted the application on IIS 7.0 server locally then system not able to find the container from the system to get the key .

Error show like "The system cannot find the file specified.".

I am saving the name of the container in database after create the container.

Please help, Its highly appreciated.
<pre> public void GenKey_SaveInContainer(string ContainerName)
{
try
{
// Create the CspParameters object and set the key container
// name used to store the RSA key pair.
CspParameters cp = new CspParameters();
cp.KeyContainerName = ContainerName;

// Create a new instance of RSACryptoServiceProvider that accesses
// the key container MyKeyContainerName.
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);

// Display the key information to the console.
//Console.WriteLine("Key added to container: \n {0}", rsa.ToXmlString(true));
string aa = rsa.ToXmlString(true);
}
catch (Exception Ex)
{
SaveExceptionInDatabase(Ex);

}
}
public string GetKeyFromContainer(string ContainerName)
{
string str = "";
try
{
// Create the CspParameters object and set the key container
// name used to store the RSA key pair.
CspParameters cp = new CspParameters();
cp.KeyContainerName = ContainerName;

// Create a new instance of RSACryptoServiceProvider that accesses
// the key container MyKeyContainerName.
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);
//AesCryptoServiceProvider AES = new AesCryptoServiceProvider(cp);


return rsa.ToXmlString(true);
// Display the key information to the console.
//Console.WriteLine("Key retrieved from container : \n {0}", rsa.ToXmlString(true));
}
catch (Exception Ex)
{
SaveExceptionInDatabase(Ex);
return str;
}
}
public void DeleteKeyFromContainer(string ContainerName)
{

try
{
// Create the CspParameters object and set the key container
// name used to store the RSA key pair.
CspParameters cp = new CspParameters();
cp.KeyContainerName = ContainerName;

// Create a new instance of RSACryptoServiceProvider that accesses
// the key container.
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);

// Delete the key entry in the container.
rsa.PersistKeyInCsp = false;

// Call Clear to release resources and delete the key from the container.
rsa.Clear();
rsa.Dispose();
}
catch (Exception Ex)
{
SaveExceptionInDatabase(Ex);

}

}</pre>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900