none
Encryption of pin number

    Question

  • I want to save 4-digit pin number to the text file(or binary file) but that pin number should be encrypted before save to in order for someone not to read it.

    How do I do this?

    Monday, April 10, 2017 8:36 PM

Answers

  • Hello,

     I would recommend you convert the PIN to an Int32 and then XOR key value.

    Where value is always know to the App. Then store the result in your file. The

    result would be useless without the XOR key value.  That is the simply approach

    as your data to encrypt is small.

    Hope this helps :)

    • Proposed as answer by cheong00Editor Tuesday, April 11, 2017 2:44 AM
    • Marked as answer by Jeff0803 Tuesday, April 11, 2017 6:31 PM
    Tuesday, April 11, 2017 12:14 AM

All replies

  • Hello,

     I would recommend you convert the PIN to an Int32 and then XOR key value.

    Where value is always know to the App. Then store the result in your file. The

    result would be useless without the XOR key value.  That is the simply approach

    as your data to encrypt is small.

    Hope this helps :)

    • Proposed as answer by cheong00Editor Tuesday, April 11, 2017 2:44 AM
    • Marked as answer by Jeff0803 Tuesday, April 11, 2017 6:31 PM
    Tuesday, April 11, 2017 12:14 AM
  • Indeed, the fact that when you apply XOR to whatever value A to form A', when perform XOR with the same key, it'll revert to A is very convenient. And it's fast too.
    Tuesday, April 11, 2017 2:39 AM
    Answerer
  • See also the Encrypt and Decrypt sample functions: https://social.msdn.microsoft.com/Forums/vstudio/en-US/d6a2836a-d587-4068-8630-94f4fb2a2aeb. The secret values like PasswordHash should be only known by you.

    Such kinds of encryption can be used with binary data too.

    • Proposed as answer by cheong00Editor Tuesday, April 11, 2017 8:08 AM
    Tuesday, April 11, 2017 6:17 AM
  • Question
    You cannot vote on your own post
    0

    Can you show me an example?

    For example, pin code is 1234 and key value is 20170411, then (pin code) XOR (key value) is 20169337, which is encrypted result.

    Later, when I want to get  pin code from encrypted result, how to do it?

    Tuesday, April 11, 2017 6:31 PM
  • You XOR the encrypted result with the same key to get the pin back.

          static void Main(string[] args)
          {
             Int32 pin = 1234;
             Int32 key = 20170411;
    
             Int32 encrypted = pin ^ key;
             Int32 decrypted = encrypted ^ key;
    
             if (decrypted == pin)
             {
                Console.WriteLine("It worked.");
             }
          }



    • Edited by Ante Meridian Wednesday, April 12, 2017 12:05 AM More tidy up.
    Wednesday, April 12, 2017 12:03 AM