I am looking for a way to encrypt and decrypt 12 digits text by 32 characters long key. The cipher must be of fixed length (32 or less). Is it possible?
Thanks in advance
I am looking for a way to encrypt and decrypt 12 digits text by 32 characters long key. The cipher must be of fixed length (32 or less). Is it possible?
Thanks in advance
Of course. With a good block cipher (like AES), you can choose between encrypting text as a block (the output will be a 32 character block) and you'll have 256 bit encryption or XORing the text with an encrypted nonce (the output will be a 12 byte ciphertext) and you'll have 96 bit encryption.
Just googling for AES and C# should come up with a ready-to-use implementation. Be sure to use a proper nonce (in some contexts also called initialization vector).
To use a hash for your purposes (see comments on this answer), proceed as follows:
Compute HASH = hash(FROM_DATE + TO_DATE + SECRET)
.
Output FROM_DATE + TO_DATE + HASH
.
+
denotes concenation and SECRET
is only known to you.
If using only capitals and numbers, it should be at least 25 characters long.
Split string into FROM_DATE + TO_DATE
and HASH
.
Verify that HASH = hash(FROM_DATE + TO_DATE + SECRET)
SHA-256 should work quite well for this.