Showing posts with label solution. Show all posts
Showing posts with label solution. Show all posts

Saturday, February 25, 2012

Assert Permission - Please Look into It

Hi All,
We are trying to find the solution for this for a very long time, hope I
can get solution for this thread.
This dll code is used to decryt the CreditCardNumber, This is working when
I use it in a web application, But I need to know what assert Permission I
need to Give to get the reult...
using System;
using System.Text;
using System.Net;
using System.IO;
using System.Collections.Specialized;
using System.Configuration;
using System.Security.Permissions;
using System.Security.Cryptography;
using FCLX509 = System.Security.Cryptography.X509Certificates;
using WSEX509 = Microsoft.Web.Services2.Security.X509;
using WSECRY = Microsoft.Web.Services2.Security.Cryptography;
namespace CreditCardDecrypt
{
/// <summary>
/// Summary description for DecryptClass.
/// </summary>
///
public class DecryptClass
{
public DecryptClass()
{
//
// TODO: Add constructor logic here
//
}
public static string DecryptCardInfo(string cc,string subjectName,string
storeName)
{
string sCreditCard = "";
try
{
WSEX509.X509CertificateStore.StoreLocation location = WSEX509.X509CertificateStore.StoreLocation.CurrentUser;
WSEX509.X509CertificateStore.StoreProvider provider = WSEX509.X509CertificateStore.StoreProvider.System;
WSEX509.X509CertificateStore store = new WSEX509.X509CertificateStore
(provider, location, storeName);
bool fopen = store.OpenRead();
if(fopen)
{
WSEX509.X509CertificateCollection certs = store.FindCertificateBySubjectString(subjectName);
if (certs.Count > 0)
{
WSEX509.X509Certificate cer = certs[0];
WSECRY.RSACryptoServiceProvider rsaCsp = (WSECRY.RSACryptoServiceProvider)cer.Key;
byte[] cipherData = Convert.FromBase64String(cc);
byte[] plainData = rsaCsp.Decrypt(cipherData, false);
sCreditCard = Encoding.UTF8.GetString(plainData);
}
}
if (store != null)
store.Close();
return sCreditCard;
//return cc;
}
catch(Exception ex)
{
return ex.ToString();
}
}
}
}
--
Message posted via http://www.sqlmonster.comWhat's the exception you get when you run the code.
It should tell you which permission needs to be asserted.
Or you can assert full trust which is less favorable due to security
reasons:
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
"BALAJI via SQLMonster.com" <forum@.nospam.SQLMonster.com> wrote in message
news:e70202f5043c49539b30bf614b8a6377@.SQLMonster.com...
> Hi All,
> We are trying to find the solution for this for a very long time, hope I
> can get solution for this thread.
> This dll code is used to decryt the CreditCardNumber, This is working when
> I use it in a web application, But I need to know what assert Permission I
> need to Give to get the reult...
> using System;
> using System.Text;
> using System.Net;
> using System.IO;
> using System.Collections.Specialized;
> using System.Configuration;
> using System.Security.Permissions;
> using System.Security.Cryptography;
> using FCLX509 = System.Security.Cryptography.X509Certificates;
> using WSEX509 = Microsoft.Web.Services2.Security.X509;
> using WSECRY = Microsoft.Web.Services2.Security.Cryptography;
> namespace CreditCardDecrypt
> {
> /// <summary>
> /// Summary description for DecryptClass.
> /// </summary>
> ///
> public class DecryptClass
> {
> public DecryptClass()
> {
> //
> // TODO: Add constructor logic here
> //
> }
> public static string DecryptCardInfo(string cc,string subjectName,string
> storeName)
> {
> string sCreditCard = "";
> try
> {
> WSEX509.X509CertificateStore.StoreLocation location => WSEX509.X509CertificateStore.StoreLocation.CurrentUser;
> WSEX509.X509CertificateStore.StoreProvider provider => WSEX509.X509CertificateStore.StoreProvider.System;
> WSEX509.X509CertificateStore store = new WSEX509.X509CertificateStore
> (provider, location, storeName);
> bool fopen = store.OpenRead();
> if(fopen)
> {
> WSEX509.X509CertificateCollection certs => store.FindCertificateBySubjectString(subjectName);
> if (certs.Count > 0)
> {
> WSEX509.X509Certificate cer = certs[0];
> WSECRY.RSACryptoServiceProvider rsaCsp => (WSECRY.RSACryptoServiceProvider)cer.Key;
> byte[] cipherData = Convert.FromBase64String(cc);
> byte[] plainData = rsaCsp.Decrypt(cipherData, false);
> sCreditCard = Encoding.UTF8.GetString(plainData);
> }
> }
> if (store != null)
> store.Close();
> return sCreditCard;
> //return cc;
> }
> catch(Exception ex)
> {
> return ex.ToString();
> }
> }
> }
> }
> --
> Message posted via http://www.sqlmonster.com

Thursday, February 16, 2012

ASP.NET,Gettting Error in the Program

Hi,

please have look into the code and let me know the solution plz.

string

ProID;try

{

using(SqlConnection conn=new SqlConnection(source))

{

conn.Open();

DataSet ds=

new DataSet();

DDLProject.Items.Clear();

SqlCommand cmd=

new SqlCommand("SP_ProjectSelect",conn);

cmd.CommandType=CommandType.StoredProcedure;

cmd.Parameters.Add("Name",SqlDbType.NChar,30,"@.Name");

cmd.UpdatedRowSource=UpdateRowSource.None;

cmd.Parameters["Name"].Value=DDLProductLine.SelectedItem;

SqlDataReader dr=cmd.ExecuteReader(); ---->>>> Here iam getting Following Error.

while(dr.Read())

{ Response.Write(dr["ID"].ToString());

}

}

}

catch(System.Exception ex)

{

Response.Write(ex);

}

Error:

System.InvalidCastException: Object must implement IConvertible. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteReader() at MIS.UI.ResourceList.DDLProductLine_SelectedIndexChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\dotnet pgms\mis\ui\resourcelist.aspx.cs:line 121

Any suggestion plzz,where went wrong.

Thanks in advance

Regards

Mahesh Reddy

Is it possible your stored procedure "SP_ProjectSelect" is not returning a result set? That's what it sounds like.|||

I think your oder in parameter.add was not correct.

The order should be SQL parameter, DataType, and Input Value.

In your case, it looks like

cmd.Parameters.Add("@.Name",SqlDbType.NChar,30,Name);

Here, "@.Name" is SQL parameter name, Name is the valueable you want to input. You can use "Name" for test. In this case, you will insert "Name" into table.

Also, NChar is not the good datatype for string name. I suggest you change it to VarChar (You need change it in SQL SP too).

Hope it helps