如何在一个应用程序中加密文本并使用另一个具有日期时间的应用程序解密相同的文本?

如何在一个应用程序中加密文本并使用另一个具有日期时间的应用程序解密相同的文本?

问题描述:

在我的Web应用程序中,我正在使用datetime创建一个加密应用程序。我复制该文本并粘贴到Web应用程序并尝试解密,它显示错误,因为日期时间。但我希望加密和解密日期时间。我是怎么做到的?



我的尝试:



我尝试并改变了很多方法。但我无法得到解决方案。所以请帮助.....

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.....

如果没有看到您的代码,以及您正在使用它做什么,我们无法告诉您这样做,它解决它。但是......你说你正在使用datetime进行加密和解密 - 这可能不是一个好的开始,因为DateTime类对Tick来说是精确的 - 可能是一万分之一秒(取决于它正在运行的系统) on,在某些情况下可能是0.034秒)

因此直接使用它作为加密密钥可能是一个非常糟糕的举动,因为你不太可能得到完全相同的值来解密它与 - 这意味着解密将失败。还有一个问题是我从未见过两台电脑完全相同的时间!在Web应用程序上发生更糟糕的事情,因为Web链接的两端不会以相同的速度接收消息 - 互联网不是即时传输系统,并且两个连续的消息需要花费不同的时间才能到达。如果您使用字符串版本作为键,问题可能会变得更糟,因为默认的DateTime.ToString不一定会给您相同的字符串,因为它取决于用户首选项。然后有时区...

用于加密和解密的密钥的任何细微差别都会给你一个问题并导致你的解密失败,所以你需要仔细思考您想要使用什么DateTime - 您甚至不能轻微地依赖于Web链接两端的相同值!
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!