473,320 Members | 1,951 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,320 software developers and data experts.

Decrypt without save the decryption: possible?

I have to read and encrypted file (with DESCryptoServiceProvider 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 1415
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********@tiscali.it> wrote:
I have to read and encrypted file (with DESCryptoServiceProvider 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.com>
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.com> wrote in
news:MP************************@msnews.microsoft.c om:
Federico Bari <fe********@tiscali.it> wrote:
I have to read and encrypted file (with DESCryptoServiceProvider
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(string cryptString)
{
try
{
SymmetricAlgorithm mCSP;
mCSP = (SymmetricAlgorithm)(new DESCryptoServiceProvider
());
mCSP.GenerateKey();
mCSP.GenerateIV();
ICryptoTransform ct = mCSP.CreateDecryptor
(mCSP.Key,mCSP.IV);
MemoryStream ms = new MemoryStream();
byte[] bytArr = Convert.FromBase64String(cryptString);
CryptoStream cs = new CryptoStream
(ms,ct,CryptoStreamMode.Write);
//write to cryptostream in memory
cs.Write(bytArr,0,bytArr.Length);
cs.Flush();
cs.Close();
return System.Text.Encoding.UTF8.GetString(ms.ToArray
());
}
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
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...
4
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...
0
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...
2
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.