Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am stuck. Please help me out.
1.its a web application in c#.net and my aim form the code below is to make two xml files, one of public key and another private key and place them in a folder within the project(here I have named it f_upload and f_upload1)but it's not happening
2.this code is not choking any error but not producing the desired files
3.is the problem on the line #1 and #2? What would be the correct line?
4.leaving #1 and #2 is the rest of the code okay to generate the desired files?
public class Class1
{
	
		public static bool GenerateRsa(int size)
        {
          /* #1 */  string privateKeyPath =  System.Web.HttpContext.Current.Server.MapPath("f_upload\\");
           /* #2 */ string publicKeyPath  = System.Web.HttpContext.Current.Server.MapPath("f_upload1\\"); 

        
    //stream to save the keys
    FileStream fs = null;
    StreamWriter sw = null;

    //create RSA provider
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(size);
    try
    {
        //save private key
        fs = new FileStream(privateKeyPath, FileMode.Create, FileAccess.Write);
        sw = new StreamWriter(fs);
        sw.Write(rsa.ToXmlString(true));
        sw.Flush();
    }
    finally
    {
        if (sw != null) sw.Close();
        if (fs != null) fs.Close();
    }

    try
    {
        //save public key
        fs = new FileStream(publicKeyPath, FileMode.Create, FileAccess.Write);
        sw = new StreamWriter(fs);
        sw.Write(rsa.ToXmlString(false));
        sw.Flush();
    }
    finally
    {
        if (sw != null) sw.Close();
        if (fs != null) fs.Close();
    }
    rsa.Clear();
    return true;
}
Posted
Updated 10-Feb-11 23:55pm
v2

You can use like below & i think, it will not make any problem.
string privateKeyPath  = Server.MapPath("~/f_upload/1.xml");
string publicKeyPath  = Server.MapPath("~/f_upload1/1.xml");

you have to, two folder f_upload & f_upload1, in the root directory in your project.
 
Share this answer
 
Comments
Supratik sadhuka 11-Feb-11 6:58am    
Thanks ma...this works..am grateful to you..
shakil0304003 11-Feb-11 7:00am    
Welcome :D
You might want to try the technique described here:

Resolving Paths in a Multi-Folder WebSite[^]
 
Share this answer
 
thanks....would it be this way i should call the function?

string s=obj.ResolvePath("C:\Documents and Settings\Soum\My Documents\Visual Studio 2008\WebSites\RSA\f_upload",whatdoigivehere?);
 
Share this answer
 

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