473,396 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Encrypt Querystring

I give up.. I tried everything to encrypt querystring and decrypt it back
but this never success.. i use RSA encryption. I always get excption when
Convert fromBase64String so i tried HttpUtitlity.UrlEncode() but i got bad
data Exception..

Is there anyway to work around this??
Jun 4 '06 #1
4 4184
To work around what? You got to show some code if you want help with it.

Islamegy® wrote:
I give up.. I tried everything to encrypt querystring and decrypt it back
but this never success.. i use RSA encryption. I always get excption when
Convert fromBase64String so i tried HttpUtitlity.UrlEncode() but i got bad
data Exception..

Is there anyway to work around this??

Jun 4 '06 #2
Here is the code i use for encrypt/decrypt

using System;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Configuration;
public class DataProtection
{
public static RSACryptoServiceProvider rsa;
public static void AssignParameter()
{
const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "NMTechnology";
CspParameters cspParams;
cspParams = new CspParameters(PROVIDER_RSA_FULL);
cspParams.KeyContainerName = CONTAINER_NAME;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
try
{
rsa = new RSACryptoServiceProvider(cspParams);
}
catch
{
string x = "X";
}
}
public static string Encrypt(string data2Encrypt)
{
AssignParameter();
StreamReader reader = new
StreamReader(ConfigurationManager.AppSettings["PublicKey"].ToString());
string publicOnlyKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicOnlyKeyXML);
reader.Close();
//read plaintext, encrypt it to ciphertext
byte[] plainbytes = System.Text.Encoding.UTF8.GetBytes(data2Encrypt);
byte[] cipherbytes = rsa.Encrypt(plainbytes, false);
return Convert.ToBase64String(cipherbytes);
}
public static void AssignNewKey()
{
AssignParameter();
//provide public and private RSA params
StreamWriter writer = new
StreamWriter(ConfigurationManager.AppSettings["PrivateKey"].ToString());
string publicPrivateKeyXML = rsa.ToXmlString(true);
writer.Write(publicPrivateKeyXML);
writer.Close();
//provide public only RSA params
writer = new
StreamWriter(ConfigurationManager.AppSettings["PublicKey"].ToString());
string publicOnlyKeyXML = rsa.ToXmlString(false);
writer.Write(publicOnlyKeyXML);
writer.Close();
}
public static string Decrypt(string data2Decrypt)
{
AssignParameter();
byte[] getpassword = Convert.FromBase64String(data2Decrypt);
StreamReader reader = new
StreamReader(ConfigurationManager.AppSettings["PrivateKey"].ToString());
string publicPrivateKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicPrivateKeyXML);
reader.Close();
//read ciphertext, decrypt it to plaintext
byte[] plain = rsa.Decrypt(getpassword, false);
return System.Text.Encoding.UTF8.GetString(plain);
}
}

"Göran Andersson" <gu***@guffa.com> wrote in message
news:u4**************@TK2MSFTNGP03.phx.gbl...
To work around what? You got to show some code if you want help with it.

Islamegy® wrote:
I give up.. I tried everything to encrypt querystring and decrypt it back
but this never success.. i use RSA encryption. I always get excption when
Convert fromBase64String so i tried HttpUtitlity.UrlEncode() but i got
bad data Exception..

Is there anyway to work around this??

Jun 4 '06 #3
I have a pretty simple sample of this:

http://blog.binaryocean.com/NETSymmetricEncryption.aspx

--

Andrew Robinson

"Islamegy®" <Is******@Private.4me> wrote in message
news:u3**************@TK2MSFTNGP03.phx.gbl...
Here is the code i use for encrypt/decrypt

using System;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Configuration;
public class DataProtection
{
public static RSACryptoServiceProvider rsa;
public static void AssignParameter()
{
const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "NMTechnology";
CspParameters cspParams;
cspParams = new CspParameters(PROVIDER_RSA_FULL);
cspParams.KeyContainerName = CONTAINER_NAME;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
try
{
rsa = new RSACryptoServiceProvider(cspParams);
}
catch
{
string x = "X";
}
}
public static string Encrypt(string data2Encrypt)
{
AssignParameter();
StreamReader reader = new
StreamReader(ConfigurationManager.AppSettings["PublicKey"].ToString());
string publicOnlyKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicOnlyKeyXML);
reader.Close();
//read plaintext, encrypt it to ciphertext
byte[] plainbytes = System.Text.Encoding.UTF8.GetBytes(data2Encrypt);
byte[] cipherbytes = rsa.Encrypt(plainbytes, false);
return Convert.ToBase64String(cipherbytes);
}
public static void AssignNewKey()
{
AssignParameter();
//provide public and private RSA params
StreamWriter writer = new
StreamWriter(ConfigurationManager.AppSettings["PrivateKey"].ToString());
string publicPrivateKeyXML = rsa.ToXmlString(true);
writer.Write(publicPrivateKeyXML);
writer.Close();
//provide public only RSA params
writer = new
StreamWriter(ConfigurationManager.AppSettings["PublicKey"].ToString());
string publicOnlyKeyXML = rsa.ToXmlString(false);
writer.Write(publicOnlyKeyXML);
writer.Close();
}
public static string Decrypt(string data2Decrypt)
{
AssignParameter();
byte[] getpassword = Convert.FromBase64String(data2Decrypt);
StreamReader reader = new
StreamReader(ConfigurationManager.AppSettings["PrivateKey"].ToString());
string publicPrivateKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicPrivateKeyXML);
reader.Close();
//read ciphertext, decrypt it to plaintext
byte[] plain = rsa.Decrypt(getpassword, false);
return System.Text.Encoding.UTF8.GetString(plain);
}
}

"Göran Andersson" <gu***@guffa.com> wrote in message
news:u4**************@TK2MSFTNGP03.phx.gbl...
To work around what? You got to show some code if you want help with it.

Islamegy® wrote:
I give up.. I tried everything to encrypt querystring and decrypt it
back but this never success.. i use RSA encryption. I always get
excption when Convert fromBase64String so i tried
HttpUtitlity.UrlEncode() but i got bad data Exception..

Is there anyway to work around this??


Jun 4 '06 #4
That looks plain and simple. How do you use the code?

Islamegy® wrote:
Here is the code i use for encrypt/decrypt

using System;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Configuration;
public class DataProtection
{
public static RSACryptoServiceProvider rsa;
public static void AssignParameter()
{
const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "NMTechnology";
CspParameters cspParams;
cspParams = new CspParameters(PROVIDER_RSA_FULL);
cspParams.KeyContainerName = CONTAINER_NAME;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
try
{
rsa = new RSACryptoServiceProvider(cspParams);
}
catch
{
string x = "X";
}
}
public static string Encrypt(string data2Encrypt)
{
AssignParameter();
StreamReader reader = new
StreamReader(ConfigurationManager.AppSettings["PublicKey"].ToString());
string publicOnlyKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicOnlyKeyXML);
reader.Close();
//read plaintext, encrypt it to ciphertext
byte[] plainbytes = System.Text.Encoding.UTF8.GetBytes(data2Encrypt);
byte[] cipherbytes = rsa.Encrypt(plainbytes, false);
return Convert.ToBase64String(cipherbytes);
}
public static void AssignNewKey()
{
AssignParameter();
//provide public and private RSA params
StreamWriter writer = new
StreamWriter(ConfigurationManager.AppSettings["PrivateKey"].ToString());
string publicPrivateKeyXML = rsa.ToXmlString(true);
writer.Write(publicPrivateKeyXML);
writer.Close();
//provide public only RSA params
writer = new
StreamWriter(ConfigurationManager.AppSettings["PublicKey"].ToString());
string publicOnlyKeyXML = rsa.ToXmlString(false);
writer.Write(publicOnlyKeyXML);
writer.Close();
}
public static string Decrypt(string data2Decrypt)
{
AssignParameter();
byte[] getpassword = Convert.FromBase64String(data2Decrypt);
StreamReader reader = new
StreamReader(ConfigurationManager.AppSettings["PrivateKey"].ToString());
string publicPrivateKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicPrivateKeyXML);
reader.Close();
//read ciphertext, decrypt it to plaintext
byte[] plain = rsa.Decrypt(getpassword, false);
return System.Text.Encoding.UTF8.GetString(plain);
}
}

"Göran Andersson" <gu***@guffa.com> wrote in message
news:u4**************@TK2MSFTNGP03.phx.gbl...
To work around what? You got to show some code if you want help with it.

Islamegy® wrote:
I give up.. I tried everything to encrypt querystring and decrypt it back
but this never success.. i use RSA encryption. I always get excption when
Convert fromBase64String so i tried HttpUtitlity.UrlEncode() but i got
bad data Exception..

Is there anyway to work around this??


Jun 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jawahar Rajan | last post by:
All, I often use a querystring in my ASP pages. for example: if val > 1 then Response.redirect "val1.asp?val=1&user=UserID End if Is there a way to encrypt the querystring so anyone trying to...
1
by: Matt | last post by:
Morning all. Does anyone have code that will allow me to encrypt a URL in c# and decrypt it in php? Myself (c#) and a fellow developer (php) at another company have had a great deal of...
3
by: TJS | last post by:
how can I encrypt the querystring values for a HyperLinkColumn ? in example below I would like to encrypt value for field1 ======================================================...
4
by: .NET Follower | last post by:
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.573 / Virus Database: 363 - Release Date: 1/28/2004
0
by: VB Programmer | last post by:
I have an ASP login page. Once logged in, I get redirected to an ASPX page. According to alot of people sharing session variables is difficult between ASP and ASPX page so I was thinking about...
3
by: TJS | last post by:
Is there a way to encrypt the url string at the application level so code does not have to be added into every page or control ?
1
by: Peter | last post by:
Hello! Is there a possibility in C# to encrypt and decrypt strings? I have a string which is passed to and ASP.NET webform as querystring. I would like to pass that string as encrypted so that...
4
by: Gary Townsend (Spatial Mapping Ltd.) | last post by:
Good afternoon, I am building an application that uses ASP .NET, and Blackmoon FTP Server, My plan currently is to automate some user processes one of those processes is to allow them to...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello to all I have a URL like this: www.servidor.com/pag.aspx?param1=v1&param2=v2 How it could encrypt and decrypt the parameters of a URL ?. Are ther some useful class that exists by...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.