Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 8th, 2006, 11:10 PM
Registered User
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to scotthcw
Default Bad data when decrypting using RSA

Hi, I found an error when I try to decrypt an encrypted array of bytes, but the following error occurs:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Security.Cryptography.CryptographicExceptio n: Bad Data.

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

//Create a new instance of the RSAParameters structure.
RSAParameters RSAKeyInfo = new RSAParameters();

//Initialize the byte arrays to the public key information.
byte[] PublicKey = {214,46,220,83,160,73,40,39,201,155,19,202,3,11,19 1,178,56,
74,90,36,248,103,18,144,170,163,145,87,54,61,34,22 0,222,
207,137,149,173,14,92,120,206,222,158,28,40,24,30, 16,175,
108,128,35,230,118,40,121,113,125,216,130,11,24,90 ,48,194,
240,105,44,76,34,57,249,228,125,80,38,9,136,29,117 ,207,139,
168,181,85,137,126,10,126,242,120,247,121,8,100,12 ,201,171,
38,226,193,180,190,117,177,87,143,242,213,11,44,18 0,113,93,
106,99,179,68,175,211,164,116,64,148,226,254,172,1 47};

byte[] Exponent = { 1, 0, 1 };

//Create values to store password
string password = txtInput.Text;
byte[] btyPwd = UnicodeEncoding.ASCII.GetBytes(password);

//Set RSAKeyInfo to the public key values.
RSAKeyInfo.Modulus = PublicKey;
RSAKeyInfo.Exponent = Exponent;

//Import key parameters into RSA.

byte[] encrypted = RSA.Encrypt(btyPwd, false);
lblOutput.Text = UnicodeEncoding.ASCII.GetString(encrypted);

//Create a new instance of the RSACryptoServiceProvider class.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
byte[] encrypted = UnicodeEncoding.ASCII.GetBytes(lblOutput.Text);
byte[] btyPwd = RSA.Decrypt(encrypted, false);
lblResult.Text = UnicodeEncoding.ASCII.GetString(btyPwd);

WHat's the problem I faced? Solution? thanks

Similar Threads
Thread Thread Starter Forum Replies Last Post
Decrypting pgp files with vbscript tonyromero99 VBScript 4 June 4th, 2008 04:09 AM
DECRYPTING Data? Thagi ASP.NET 1.x and 2.0 Application Design 1 March 28th, 2006 05:46 PM
Bad Data Error chiefg General .NET 1 March 4th, 2006 03:09 AM
problem decrypting bluelaser General .NET 0 October 10th, 2004 10:18 AM
Encrypting and Decrypting chipset VB How-To 0 July 27th, 2004 07:36 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.