|
Hi,
I am trying to use RSACryptoServiceProvider in my ASP.NET application to access keys from a MachineKeyStore on my computer, running windows xp and IIS 5.
I created machinekeystore like following in Visual Studio 2005 Command Prompt:
aspnet_regiis -pc "CustomKeys" -exp (command was successful)
Then I executed following command because I am impersonating my web application with a non-default user:
aspnet_regiis -pa "CustomKeys" "domain\auserforapplication" (command was successful)
Then I worte the following code:
public partial class Examples_EncryptionExample : System.Web.UI.Page<br />
{<br />
CspParameters CspParam;<br />
string publicXmlString = string.Empty;<br />
string privateXmlString = string.Empty;<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
byte [] encrypted;<br />
string decrypted;<br />
<br />
UnicodeEncoding ByteConverter = new UnicodeEncoding();<br />
encrypted = EncrptData("data to encrypt");<br />
Response.Write(System.Text.Encoding.Unicode.GetString(encrypted));<br />
decrypted = DecryptData(encrypted);<br />
Response.Write(decrypted);<br />
}<br />
catch (Exception ex)<br />
{<br />
}<br />
}<br />
<br />
public string DecryptData(byte [] data)<br />
{<br />
RSACryptoServiceProvider RsaCsp;<br />
byte[] decryptedData;<br />
RsaCsp = new RSACryptoServiceProvider();<br />
RsaCsp.FromXmlString(privateXmlString);<br />
decryptedData = RsaCsp.Decrypt(data, false);<br />
return System.Text.Encoding.Unicode.GetString(decryptedData);<br />
}<br />
<br />
public byte [] EncrptData(string data)<br />
{<br />
RSACryptoServiceProvider RsaCsp;<br />
RSACryptoServiceProvider RsaCsp2;<br />
UnicodeEncoding ByteConverter = new UnicodeEncoding();<br />
CspParam = new CspParameters();<br />
CspParam.KeyContainerName = "CustomKeys";<br />
CspParam.Flags = CspProviderFlags.UseMachineKeyStore;<br />
<br />
byte[] encryptedData = ByteConverter.GetBytes(data);<br />
<br />
RsaCsp = new RSACryptoServiceProvider(CspParam);<br />
<br />
publicXmlString = RsaCsp.ToXmlString(false);<br />
privateXmlString = RsaCsp.ToXmlString(true);<br />
<br />
RsaCsp2 = new RSACryptoServiceProvider();<br />
RsaCsp2.FromXmlString(publicXmlString);<br />
encryptedData = RsaCsp2.Encrypt(System.Text.Encoding.Unicode.GetBytes(data), false);<br />
<br />
return encryptedData;<br />
}<br />
}
The problem over here is that when ever I try to execute the above mentioned code. Code encrypts the data fine
but when it comes at decrypting the data, throws following exception:
<br />
Exception Details: System.Security.Cryptography.CryptographicException: The system cannot find the file specified.<br />
<br />
<br />
Source Error: <br />
<br />
<br />
Line 35: byte[] decryptedData;<br />
Line 36: RsaCsp = new RSACryptoServiceProvider();<br />
Line 37: RsaCsp.FromXmlString(privateXmlString);<br />
Line 38: decryptedData = RsaCsp.Decrypt(data, false);<br />
Line 39: return System.Text.Encoding.Unicode.GetString(decryptedData);<br />
<br />
<br />
Source File: c:\Data\iis\www\DefaultWeb\Phoenix\Admin\Examples\EncryptionExample.aspx.cs Line: 37 <br />
<br />
Stack Trace: <br />
<br />
<br />
[CryptographicException: The system cannot find the file specified.<br />
]<br />
System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr) +33<br />
System.Security.Cryptography.Utils._CreateCSP(CspParameters param, Boolean randomKeyContainer, SafeProvHandle& hProv) +0<br />
System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer) +201<br />
System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters parameters) +262<br />
System.Security.Cryptography.RSA.FromXmlString(String xmlString) +465<br />
Examples_EncryptionExample.DecryptData(Byte[] data) in c:\Data\iis\www\DefaultWeb\Phoenix\Admin\Examples\EncryptionExample.aspx.cs:37<br />
Examples_EncryptionExample.Page_Load(Object sender, EventArgs e) in c:\Data\iis\www\DefaultWeb\Phoenix\Admin\Examples\EncryptionExample.aspx.cs:28<br />
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15<br />
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34<br />
System.Web.UI.Control.OnLoad(EventArgs e) +99<br />
System.Web.UI.Control.LoadRecursive() +47<br />
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
I could control the above mentioned error by doing a nasty trick which is. The account "domain\auserforapplication" which I am impersonating my application with. I used a utility in windows xp accessible from "All Programs/Accessories/System Tool/Schedule Tasks" to create a process e.g. executed calc.exe application under the account "domain\auserforapplication". Everything started working fine. No error nothing.
A million dollar question is why did I get the above mentioned error at the first place? Why did I had to start a new process under the indentity of my application on my machine.
If somebody could answer my question. I will highly appreciate that because then I have another question regarding exporting the keys to Windows 2003 Server and using keys over there. That problem is even more nasty.
For now I will highly appriciate if somebody could answer my current question.
Thanks
|
|
|
|
|
Hi,
I have a ascx page ItemEdit.ascx. It contains a combobox. This control dynamically added to a aspx page.
Now the problem is that i am unable to catch the event(selectedindexchange)of combobox in ItemEdit.ascx control.
How will i overcome this problem.
plz help me this is very urgent.
Thanks n Regards,
Alok....
|
|
|
|
|
If you want to catch the event inside the user control itself, that will not be a problem. For that you can double click on the combobox while in design mode and enviorment will auto generate the handler for the SelectedIndexChanged event by default in side the code behind for .ascx file. But don't forget to set the "AutoPostBack" property of the dropdownbox to true.
If you want to handle SelectedIndexChanted even inside your page where you are using this user control then the quickest souloution is as follows:
Create a public property in your user control like:
public DropDownList List
{
return ddlYourTargetComboBox;
}
on your page do something like:
ucYourUserControlInstance.List.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
void list_SelectedIndexChanged(object sender, EventArgs e)
{
//Implement logic here
}
Hope this helps
|
|
|
|
|
And also add AutoPostBack Property = true along with the above code.
Regards,
Arun Kumar.A
|
|
|
|
|
Hello friends,
I am using rad menu in my project..i want to give a css for that rad menu.
can anybody help me to solve this...if possible give me a small eg or something useful...
regards alex
|
|
|
|
|
Hi all,
I use CssClass for a link(href) but a:active selector dose not worked and I don't know that this error why happned.
|
|
|
|
|
Always try and give some meaningful subject to your question, that will be a lot easier for the people who are here to help you.
Provide some code snippet so that we can help you pointing out the mistake
Mubashir
Software Architect
Storan Technologies Inc, USA
Every job is a self portrait of the person who did it.
|
|
|
|
|
when i was using VS.NET 2005, can't see other classes in one namespase.
In VS.NET 2003 all works.
All classes are public.
|
|
|
|
|
sounds strange...but compile successfully or not?
<< >>
|
|
|
|
|
|
Hi,
I using .NET 2.0. I want to use a cust create user control, but I am struggling to change the text of the default button from Create User to Register. Please can someone advise me on how to do this.
Also, where does the user get added to the user membership tables??
I hope someone can help?
Regards
ma se
|
|
|
|
|
set CreateUserButtonText property to "Register"
<< >>
|
|
|
|
|
Hello Everyone,
I am trying to have my site connect to a database a check for an email address but when it goes to open the database I receive an error.
Here is the code up until I receive the error. Can anyone see if I am missing something?
Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class login
Inherits System.Web.UI.Page
Private Function emailCheck() As Boolean
Dim conCED As SqlConnection
Dim cmdSelect As SqlCommand
Dim dtrLogin As SqlDataReader
Dim path As String
Dim provider As String
path = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DatabaseSQL.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
provider = "Database=DatabaseSQL;"
conCED = New SqlConnection(provider & path)
conCED.Open()
On the conCED.Open() I get this error message.
The header for file 'e:\wwwdata\56b549be\www\App_Data\DatabaseSQL.mdf' is not a valid database file header. The FILE SIZE property is incorrect.
Could not attach file 'e:\wwwdata\56b549be\www\App_Data\DatabaseSQL.mdf' as database 'DatabaseSQL'
Thanks for the help
Chad Dolan
|
|
|
|
|
Just to make sure to verity if DB is ok or not...can you open your DB thru SQL enterprise?
<< >>
|
|
|
|
|
I think you are right there is a problem with the DB.
Thanks for the help.
Chad Dolan
|
|
|
|
|
Hi everybody...
I have some problems related to a querystring issue.
I`m calling an ASPX page, with some querystring parameters, from a JavaScript function, through the window.open method.
The way this URL is configured and called in the javascript function is the following: EnviarMapaEmail.aspx?type=addPt&x=-46.644203856241546&y=-23.571182563934798&st=Av.%20Paulista&nb=10&city=S%C3O%20PAULO&uf=SP&POI=
And in the ASPX page, the Request.QueryString comes this way:
type=addPt&x=-46.644203856241546&y=-23.571182563934798&st=Av.+Paulista&nb=10&city=SO+PAULO&uf=SP&POI=
The problem is: the original city name (city parameter) is 'SÃO PAULO' and it`s encoded in the URL (thought the escape() javascript function) as 'S%C3O%20PAULO', but my ASPX page only recognize'SO+PAULO' and it goes back through the Request.QueryString as 'SO PAULO'.
What`s the problem in encoding especial chars?
Any hint would be very appreciated... :]
See you!
|
|
|
|
|
AFAIK, the settings that decide how the escaped codes in the request are decoded are:
:: The content-type setting in the html header, which probably comes from:
:: The content-type meta tag in the sending page.
:: The RequestEncoding setting in the web.config file.
Also, the escape function might not take into account the selected encoding for the page. Try the newer encodeURIComponent function instead.
---
single minded; short sighted; long gone;
|
|
|
|
|
hey guffa...
thank you, it worked.
both pages are .aspx, so, presumably, they`re using the same encoding type.
but your hint about the encodeURIComponent function worked fine, both on IE and FF.
cya
|
|
|
|
|
Hello,
How can I make an ASP.Net page execute a certain function every 30 minutes ?
tnX...
|
|
|
|
|
Java Script:
===========
function setTimeInterval()
{
var Timer = setInterval("fun()", 30*1000); //For every 30 minutes fun() will be executed.
}
function fun()
{
Ur Code Here
}
<body onLoad="setTimeInterval()">
Regards,
Arun Kumar.A
|
|
|
|
|
other way...
<!-- Refresh page after 10 seconds --><br />
<meta http-equiv="refresh" content="10" />
<< >>
|
|
|
|
|
Hi Al,
Manoj Bisht this side. Can anybody let me know how to deploy an web application in ASP.NET and also is it necessary to include the database(Sql Server2000) while deploying the web application if yes how it can be
.....................
Plz
|
|
|
|
|
The Knowledge wrote: how to deploy an web application in ASP.NET and also is it necessary to include the database(Sql Server2000) while deploying the web application
Assume that you are deploying to remote server. Copy all aspx files, and config files. Copy bin folder also which contains all dll's. SQL DB can be deployed as a .SQL file.
|
|
|
|
|
Hi all,
Can anybody let me know how to include the splash screen in ASP.NET(Web Based)
or in javascript as well
...............................
Manoj Bisht
|
|
|
|
|
hello
who r u?
do u know who am i.
the big legend there.
byee
tc
|
|
|
|