Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my web application i am creating one encryption application with datetime. And i copy that text and paste in web application and try to decrypt, it shows error because of datetime. But i want encryption and decryption with datetime. How i do that?

What I have tried:

I tried and change lot of methods. But i cannot get solutions. So please help.....
Posted
Updated 15-Jun-16 19:54pm
Comments
Sergey Alexandrovich Kryukov 16-Jun-16 1:43am    
You need to get familiar with the basics of cryptography. Public-key or symmetric encryption? How your key distribution should look like? What's the purpose? Who should get access to what and who should be denied access?
What does it mean, nt encryption and decryption with datetime? What error?
—SA
CPallini 16-Jun-16 2:26am    
Using the current datetime as encryption key is definitely a bad move.

1 solution

Without seeing your code, and exactly what you are doing with it, we can't tell you "do this, it'll fix it". But...you say you are "using datetime" to encrypt and decrypt - that's possibly not a good start, as the DateTime class is precise to the Tick - which may be one 10,000,000th of a second (depends on the system it's running on, it may be 0.034 of a second in some)
So using it directly as an encryption key may be a very bad move, as it's very unlikely that you will get exactly the same value to decrypt it with - which means the decryption will fail. And there is also the problem that I've never seen two computers with exactly the same time! On a web application there is even worse stuff happening as the two ends of the web link won't receive messages at the same speed - the internet is not an "instant transmission" system, and two successive messages an take wildly differing times to arrive. If you use the string version as a key, the problem may even get worse, as the default DateTime.ToString will not necessarily give you the same string, as it depends on the user preferences. And then there is time zones...
Any slight difference in the key used for encryption and decryption will give you a problem and cause your decryption to fail, so you need to think long and hard about exactly what DateTime you want to use - you can't even slightly depend on it being the same value at two ends of a web link!
 
Share this answer
 
Comments
CPallini 16-Jun-16 2:25am    
5.
Member 10556393 16-Jun-16 2:34am    
I accept your solution. But what is the best way to create encryption and decryption. Each and every time i want different encrypt text for the same input also.
OriginalGriff 16-Jun-16 2:47am    
The problem is that encryption only works if the decryption software has the same key - so trying to vary the key each time causes problems as the decryption has to either be sent the key (insecure) or work out how to create it (also insecure, because if it can do it, so could I)
What exactly are you trying to do?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900