I use VS2008, and I encrypted a file using this function: -
public static void Encrypt(string fileIn, string fileOut, string Password)
-
{
-
-
FileStream fsIn = new FileStream(fileIn,
-
FileMode.Open, FileAccess.Read);
-
FileStream fsOut = new FileStream(fileOut,
-
FileMode.OpenOrCreate, FileAccess.Write);
-
-
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
-
new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
-
0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
-
-
Rijndael alg = Rijndael.Create();
-
alg.Key = pdb.GetBytes(32);
-
alg.IV = pdb.GetBytes(16);
-
-
CryptoStream cs = new CryptoStream(fsOut,
-
alg.CreateEncryptor(), CryptoStreamMode.Write);
-
-
int bufferLen = 4096;
-
byte[] buffer = new byte[4096];
-
int bytesRead;
-
-
do
-
{
-
bytesRead = fsIn.Read(buffer, 0, bufferLen);
-
-
cs.Write(buffer, 0, bytesRead);
-
} while (bytesRead != 0);
-
-
cs.Close();
-
fsIn.Close();
-
}
-
Now I tried to make a function that will convert an encoded BMP file to bitmap and when it gets to the return line it says "A generic error occurred in GDI+."
Here is the function: -
public static Bitmap DecryptToBitmap(string fileIn, string Password)
-
{
-
FileStream fsIn = new FileStream(fileIn, FileMode.Open, FileAccess.Read);
-
-
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
-
new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
-
0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
-
Rijndael alg = Rijndael.Create();
-
-
alg.Key = pdb.GetBytes(32);
-
alg.IV = pdb.GetBytes(16);
-
-
MemoryStream ms = new MemoryStream();
-
-
CryptoStream cs = new CryptoStream(ms,
-
alg.CreateDecryptor(), CryptoStreamMode.Write);
-
-
int bufferLen = 4096;
-
byte[] buffer = new byte[4096];
-
int bytesRead;
-
-
do
-
{
-
bytesRead = fsIn.Read(buffer, 0, bufferLen);
-
-
cs.Write(buffer, 0, bytesRead);
-
-
} while (bytesRead != 0);
-
-
fsIn.Close();
-
-
byte[] decryptedData = ms.ToArray();
-
-
MemoryStream img = new MemoryStream(decryptedData);
-
-
return new Bitmap(img);
-
}
-
Please help me figure out the problem.
Thanks in advance.
2 1592
It sounds like something might be going wrong in your decryption/encryption scheme. Have you tried matching the byte arrays that represent the Bitmap before and after encryption?
It sounds like something might be going wrong in your decryption/encryption scheme. Have you tried matching the byte arrays that represent the Bitmap before and after encryption?
I have another function that decrypts the file to another file. and it works perfectly. only when I run the one that decrypts to bitmap it doesn't work..
this is the decrypt function: -
public static void Decrypt(string fileIn, string fileOut, string Password)
-
{
-
-
FileStream fsIn = new FileStream(fileIn,
-
FileMode.Open, FileAccess.Read);
-
FileStream fsOut = new FileStream(fileOut,
-
FileMode.OpenOrCreate, FileAccess.Write);
-
-
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
-
new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
-
0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
-
Rijndael alg = Rijndael.Create();
-
-
alg.Key = pdb.GetBytes(32);
-
alg.IV = pdb.GetBytes(16);
-
-
CryptoStream cs = new CryptoStream(fsOut,
-
alg.CreateDecryptor(), CryptoStreamMode.Write);
-
-
int bufferLen = 4096;
-
byte[] buffer = new byte[4096];
-
int bytesRead;
-
-
do
-
{
-
bytesRead = fsIn.Read(buffer, 0, bufferLen);
-
-
cs.Write(buffer, 0, bytesRead);
-
-
} while (bytesRead != 0);
-
-
cs.Close();
-
-
fsIn.Close();
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jase H |
last post by:
Hello,
I have a ASP.NET web application problem involving the data encryption and
decryption assembly(DLL) used on the connection string value that is set in
the webconfig file.
The problem occurs in the application when you instantiate a new instance of
the class as shown below:
---Dim dp As DPAPIComp.DataProtectorComp = New DPAPIComp.DataProtectorComp---
where DPAPIComp is the name of the namespace referenced to in the library
|
by: Martin |
last post by:
Hi
Im trying to make a Client/Server where im going to encrypt the stream but i cant get it to work. I can recieve and send as long as im not trying to send/recieve encrypted. but when i am i cant send, recieve or both.
The Send/Recieve Code is the same on both Server and client.
Send/Recieve Code:
private Stream Net()
{
if(Encrypted)
{
|
by: almurph |
last post by:
Hi everyone,
Can you help me please? I am having a problem with the
encryption/decryption of words with the Irish fada in them. The Irish
fada is like this: áéíóú/ÁÉÍÓÚ. It's kind of like the French
grave...
Anyway when I run encryption on a plaintext word like:
|
by: Showjumper |
last post by:
I solved my previous problem. The new one is that the password is not being
decrypted but rather is still in the enrypted format. I am using Rijndael
emcryption. Below is the decryption code.
And here is th eline to return the decrypted password. Any help is
appreciated Thanks Ashok
Return s.DecryptToString(encryptedData,
CType(HttpContext.Current.Application("Key"), Rijndael))
Public Shared Function DecryptToString(ByVal dataToDecrypt...
|
by: DarkProtoman |
last post by:
How would I write a function to calculate RSA Decryption key. I'm
trying to write an RSA encryption program, and I'm stuck on calculating
the decryption key. How do you check for coprimality? Thanks!!!!! I'm
using C++.
| |
by: nithyapriya |
last post by:
Hai,
I'm nithya. I have a visual basic program that decrypts a file from my client using a passphrase.
My seniors have no problem in the decryption.
As I'm new to this concept, i could not proceed in it.
The problem is,
My client sends me the public key, say for eg, Key.txt
I import the file (Key.txt) in my gpg.
The public key gets stored in my gpg (pubring.gpg)
But I could not find my secret key in my gpg (secring.gpg)
|
by: Dipanwita |
last post by:
I have written a RSA encryption/decryption function in c using the formula a = b^c %n. For solving the equation I have used Squaring and multiplying method for modulo exponentiation .
These functions work fine when Two random prime numbers (required to generate public n private key) are within certain range but fails afterwords.All the variables are of datatype ULONGLONG. I m unable to fix up the problem. Is these really a storage problem...
|
by: =?Utf-8?B?TG9yZW4=?= |
last post by:
I’m trying to encrypt and decrypt a file in vb.net. I am using the
TripleDESCryptoServiceProvider encryption found in
System.Security.Cryptography. Below is the code for my Encrypt and Decrypt
functions.
While my functions read and write files the encryption/decryption is not
working properly. My test file has an original length of 66,048 bytes. My
encrypted file ends up with 66,056 bytes … 8 bytes more than my original.
When I...
|
by: Tom Andrecht |
last post by:
I'm trying to get some encryption/decryption routines going to take care of
my data, and while the encryption is working great, I keep running into the
message "Padding is invalid and cannot be removed" on the decryption piece.
From everything I can see, I am doing things correctly here My code is as
follows:
private const string PassStr = "MyPrivateKey";
private static readonly byte PassSalt = new byte { Byte Byte
Byte Byte Byte};...
|
by: Betikci Boris |
last post by:
I get bored last night and wrote a script that uses xor for encrypt-
decrypt, however it woks fine under linux 2.6.25, text and documents
are ok, but fails on compressed files *.jpg, *.pdf , etc . I didn't
test script on windows.
Here is the code, please send me your views.
<?php
/* Mother Eye Chipper with PHP :), Licence:GPL,
|
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...
| |
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |