Encrypt and Decrypt DateTime to another DateTime

samwatson

New member
Joined
Dec 12, 2022
Messages
2
Programming Experience
5-10
Hi
How do I encrypt and decrypt one datetime to another? I can easily encrypt and decrypt using AES, however the result is a string. I want the output to be a Datetime. How can I accomplish that?
Thanks
 
There is no such thing. All encryption is done on binary data, i.e. bytes, and the result is binary data, i.e. bytes. That's it, that's all. You can then convert the result bytes to a string if you want, using hexadecimal or base 64, but that's an extra step.

The only way you could do what you want is if you could use an encryption method that would output the exact amount of binary data needed to represent a DateTime. You would then convert one value to bytes, encrypt that, then convert the result to a DateTime. The DateTime.ToBinary and .FromBinary methods work with 64-bit numbers, so if you can find a way to encrypt 8 bytes to 8 bytes then you're good to go. Otherwise, you're screwed.
 
I can easily encrypt and decrypt using AES, however the result is a string.
That is not true. AES encrypts a series of bytes to another series of bytes. The output bytes though tend to be bigger than the input of bytes when AES due to the nature of the algorithm working with blocks of bytes at a time. I think that it just so happens that whatever code or script you are using to do the encryption is then taking the encrypted series of bytes and returning you either the hexdecimal or base64 representation.
 
May you suggest any way to convert "int to another int" and "datetime to another datetime" and back? There is no need to use any encryption method but definitely it must hard to get to the original data.
 
A simple XOR is usually good enough for lightweight obfuscation/encryption.
 
Back
Top Bottom