Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi,I am in need of sample program to display the encrypted image ,someone pls help me
 
This is the code for encryption.But I got a error like "key not valid for use in specified state"
byte[] img = imagetobyte(pictureBox1.Image);
RSAParameters rsaPubParams;
RSAParameters rsaPrivateParams;
RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
 
//Generate public and private key data.
rsaPrivateParams = rsaCSP.ExportParameters(true);
rsaPubParams = rsaCSP.ExportParameters(false);
rsaCSP.ImportParameters(rsaPubParams);
byte[] output=new byte[13000000];
output = rsaCSP.Encrypt(img,false);
pictureBox2.Image = byteArrayToImage(output);
how to rectify it?
 
[Edit: Codehawkz]Added the user comments to the question itself[/edit]
Posted 19-Sep-12 20:38pm
Edited 19-Sep-12 22:39pm
CodeHawkz4.1K
v2
Comments
Kuthuparakkal at 20-Sep-12 2:41am
   
need more info
prabhatsp at 20-Sep-12 2:49am
   
I need the program which use image(flower something) as input , i want perform encryption process with key and image.Then I have to display the encrypted image(something like image full of dot,but something to be displayed) as output
prabhatsp at 20-Sep-12 3:21am
   
The code using AES Encryption performs encryption ,but the image will not be displayed.
DaveAuld at 20-Sep-12 2:41am
   
That is just a horrendous question. What encryoted image? What encryption scheme? What have you tried?
prabhatsp at 20-Sep-12 2:49am
   
I need the program which use image(flower something) as input , i want perform encryption process with key and image.Then I have to display the encrypted image(something like image full of dot,but something to be displayed) as output
CodeHawkz at 20-Sep-12 2:52am
   
Prabhat, let's imagine you make customized cages for animals. If i come and ask Hi, 'I am in need a cage to put my pet', what would you say? You'll first be like 'errm.. crazy guy' and ask 'what do you have for a pet? what is the size of it?' and so on. Because, without that it's impossible for you to come up with a cage with correct size. isn't it?
 
Likewise, we can't either. The other difference is, we are not doing a business here. So give us all the relevant information you got, so that we can help you. A few examples, explanation of the problem you faced, sample code, etc. would be really nice. Otherwise people wouldn't even bother to help you (even though I took this time to type all this hoping you'd learn how to explain a problem of yours to someone else).
 
How do you expect someone to know that image was encrypted using what method?
 
Please, improve your question
prabhatsp at 20-Sep-12 3:01am
   
Mr.CodeHawkz,I use original image size of (120,120).I convert image to byte array.I use RSA encryption algorithm.This is the code for encryption.But I got a error like "key not valid for use in specified state"
byte[] img = imagetobyte(pictureBox1.Image);
RSAParameters rsaPubParams;
RSAParameters rsaPrivateParams;
RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
 
//Generate public and private key data.
rsaPrivateParams = rsaCSP.ExportParameters(true);
rsaPubParams = rsaCSP.ExportParameters(false);
rsaCSP.ImportParameters(rsaPubParams);
byte[] output=new byte[13000000];
output = rsaCSP.Encrypt(img,false);
pictureBox2.Image = byteArrayToImage(output);
how to rectify it .
CodeHawkz at 20-Sep-12 4:43am
   
Hi, I added this part of your question to the question itself. What you need to realize is that, an image is a certain format of bytes, not just some bytes. When you encrypt you destroy this format and it becomes a meaningless set of bytes. Therefore, you cannot display it, unless you decrypt back again
 
I get what you mean by an encrypted image. Let me get back to you on that :)
 
Regards
prabhatsp at 20-Sep-12 5:35am
   
Hi,any concept related to displaying image encryption
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If you do not know the encryption standard and the keys/passwords/etc. used to encode the original image, you will not be able to decrypt it without some serious hacking skills (and in many cases, it's not possible even with such skills).
 
There's a code sample in this forum that shows how to implement both encryptions and decryption in 2 small projects:
Encrypt and decrypt images
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

RSA can only encrypt data blocks that are shorter than the key length. Try AES and encrypt the data using a random key with AES and encrypt the random key with RSA key.
  Permalink  
Comments
Kuthuparakkal at 20-Sep-12 3:28am
   
I think you are confused with encryption and "the stuff" you would like to achieve. You either look for :
1. Image Distortion
 
OR
2. Scramble/De-scarmble stuffs.
 
http://www.codeforge.com/article/211089
http://en.wikipedia.org/wiki/Bilinear_interpolation
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To show an encrypted image first you must "decrypt" it to the original format.
 
For this you must know the encryption method and keys used.
 
The standard libraries in .net can show most image formats (png,jpg,gif etc.) without problems.
  Permalink  
Comments
DaveAuld at 20-Sep-12 2:55am
   
Reading his comments, I think he is talking more about image scrambling, as he wants to still be able to show a valid image of the encrypted input image.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 766
1 OriginalGriff 345
2 CPallini 200
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,028
2 CPallini 4,700
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100