none
Writing a very simple encryption tool for a login RRS feed

  • Question

  • Hello! I'm looking for a simple, easy, and very non-complicated way to encrypt a string.

    Basically, I'm saving a 4-character PIN to an XML file and I'm wanting to just hide its true value while allowing a user to login using that PIN. Security is such a non-issue that I don't even have to encrypt the PIN, I'm just wanting to do it. So the easier the solution the better.

    Imagine the user creates a PIN of '1234'. That PIN is saved in the XML file as <PIN>1234</PIN>.

    When the user logs back in, I just need to be able to take their input and compare it against the value in <PIN>. If it matches, they're logged in.

    Any recommendations?

    Thanks!

    Monday, February 18, 2019 9:11 PM

Answers

  • If you're really not worried about making the encryption difficult to crack, the simplest way is to just add some number to the original and store the result as 5 digits. To decrypt, subtract the number and use the least significant four digits.

    Example : Key (number to add/subtract) = 1010, PIN = 9876, encrypted number = 9876 + 1010 = 10886, decrypted = 10886 - 1010 = 9876

    If your car radio stops working whenever you change the battery (as mine does), you will probably find the security code needed to re-activate it is written on the radio somewhere and encrypted something like the above.

    • Marked as answer by T Gregory Tuesday, February 19, 2019 4:38 AM
    Monday, February 18, 2019 11:00 PM

All replies

  • https://medium.com/@mehanix/lets-talk-security-salted-password-hashing-in-c-5460be5c3aae

    The solution should be using a database table. A XML file is not an optimal approach and not a secure one IMO. .

    Monday, February 18, 2019 10:05 PM
  • If you're really not worried about making the encryption difficult to crack, the simplest way is to just add some number to the original and store the result as 5 digits. To decrypt, subtract the number and use the least significant four digits.

    Example : Key (number to add/subtract) = 1010, PIN = 9876, encrypted number = 9876 + 1010 = 10886, decrypted = 10886 - 1010 = 9876

    If your car radio stops working whenever you change the battery (as mine does), you will probably find the security code needed to re-activate it is written on the radio somewhere and encrypted something like the above.

    • Marked as answer by T Gregory Tuesday, February 19, 2019 4:38 AM
    Monday, February 18, 2019 11:00 PM

  • static string ProtectPass(string clearPassword)
            {
                byte[] bytes = Encoding.UTF8.GetBytes(clearPassword);
                return Convert.ToBase64String(bytes); //protectedBytes
            }


    static string UnProtectPass(string protectedPassword)
            {
                byte[] protectedBytes = Convert.FromBase64String(protectedPassword);
                return Encoding.UTF8.GetString(protectedBytes); //bytes
            }


    • Proposed as answer by rprst Wednesday, February 20, 2019 8:56 PM
    Tuesday, February 19, 2019 12:00 AM
  • Perfect! Thanks.
    Tuesday, February 19, 2019 4:38 AM