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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
Hashing:
Compute
HASH = hash(FROM_DATE + TO_DATE + SECRET).Output
FROM_DATE + TO_DATE + HASH.+denotes concenation andSECRETis only known to you.If using only capitals and numbers, it should be at least 25 characters long.
Verification:
Split string into
FROM_DATE + TO_DATEandHASH.Verify that
HASH = hash(FROM_DATE + TO_DATE + SECRET)SHA-256 should work quite well for this.