473,770 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Decrypt without save the decryption: possible?

I have to read and encrypted file (with DESCryptoServic eProvider class) and
decrypt it without save the clear file in the disk!!! ie i'd like to have
the decryption in a string variable because for safe reasons i cannot save
the decription in the disk even if for a short time. The CryptoStream seem
to work only with in and out files; do somebody know how i can do? Thank you
very much.

Federico.



Nov 15 '05 #1
3 1449
You can use a memorystream instead of filestream.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2
Federico Bari <fe********@tis cali.it> wrote:
I have to read and encrypted file (with DESCryptoServic eProvider class) and
decrypt it without save the clear file in the disk!!! ie i'd like to have
the decryption in a string variable because for safe reasons i cannot save
the decription in the disk even if for a short time. The CryptoStream seem
to work only with in and out files; do somebody know how i can do? Thank you
very much.


No, CryptoStreams work with *streams*, not files. You can use a memory
stream, for instance. If you *really* want the result in a string
variable rather than a byte array, I suggest Base64 encoding the binary
data.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote in
news:MP******** *************** *@msnews.micros oft.com:
Federico Bari <fe********@tis cali.it> wrote:
I have to read and encrypted file (with DESCryptoServic eProvider
class) and decrypt it without save the clear file in the disk!!! ie
i'd like to have the decryption in a string variable because for safe
reasons i cannot save the decription in the disk even if for a short
time. The CryptoStream seem to work only with in and out files; do
somebody know how i can do? Thank you very much.


No, CryptoStreams work with *streams*, not files. You can use a memory
stream, for instance. If you *really* want the result in a string
variable rather than a byte array, I suggest Base64 encoding the
binary data.


Please consider the following code, where cryptString is the filetext:

private string DecryptText(str ing cryptString)
{
try
{
SymmetricAlgori thm mCSP;
mCSP = (SymmetricAlgor ithm)(new DESCryptoServic eProvider
());
mCSP.GenerateKe y();
mCSP.GenerateIV ();
ICryptoTransfor m ct = mCSP.CreateDecr yptor
(mCSP.Key,mCSP. IV);
MemoryStream ms = new MemoryStream();
byte[] bytArr = Convert.FromBas e64String(crypt String);
CryptoStream cs = new CryptoStream
(ms,ct,CryptoSt reamMode.Write) ;
//write to cryptostream in memory
cs.Write(bytArr ,0,bytArr.Lengt h);
cs.Flush();
cs.Close();
return System.Text.Enc oding.UTF8.GetS tring(ms.ToArra y
());
}
catch(Exception e)
{
MessageBox.Show (e.Message);
}
return "";
}

This should work as needed.

aacool
Nov 15 '05 #4

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

Similar topics

7
17879
by: Dica | last post by:
i've used the sample code from msdn to create an encyption/decryption assembly as found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp i'm able to encrypt and then decrypt data okay as in the following code: // encrypt the data // Encryptor enc = new Encryptor(EncryptionAlgorithm.TripleDes); byte key = Encoding.ASCII.GetBytes("0123456789012345");
4
2595
by: hohans | last post by:
Hi all, I have an encryption class that encrypts and decrypts password using TripleDESCryptoServiceProvider. It was written originally in framework 1.0 and been working fine. And those passwords are stored in my SQL server. Now I need to migrate my application to framework 2.0. I use this same class with framework 2.0 library to decrypt the passwords from database (of course, they were encrypted in 1.0) but getting "Bad Data"
0
3373
by: Hannibal111111 | last post by:
I found this code on a site for doing string encryption/decryption. The string will encrypt fine, but I get this error when I try to decrypt. Any idea why? I posted the code below. The error actually points to this line of code in byte decrypt function: cs.FlushFinalBlock(); public static byte encrypt(byte clearData, byte Key, byte IV)
2
7693
by: Bernard Dhooghe | last post by:
The information center writes: "Encryption Algorithm: The internal encryption algorithm used is RC2 block cipher with padding, the 128-bit secret key is derived from the password using a MD2 message digest. " and also explains how the length of the encrypted column can be derived.
0
9618
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.