Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Locking data to user

Locking data to user

Scheduled Pinned Locked Moved C#
securityquestiondata-structureshelplearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dominik Reichl
    wrote on last edited by
    #1

    Hello! I'm trying to write a tool that associates some data with the currently logged on Windows user account. I.e. the encryption key for the file is generated based on the user. How can I do this? Of course, just using the user name is bad, because it should also depend on the users password. Unfortunately I haven't found a function to get the user's password (is there one?). I tried using the System.Security.Cryptography.ProtectedData.Protect function. The problem with this approach is that this function returns a byte array that includes a seed. I.e. when calling this function twice, you'll never get the same results. But this is a requirement, as I want to use its output only as key for my own encryption engine (which offers choice between different algorithms, like AES, Twofish, ...). Best regards Dominik


    Too many passwords to remember? Try KeePass Password Safe!

    D 1 Reply Last reply
    0
    • D Dominik Reichl

      Hello! I'm trying to write a tool that associates some data with the currently logged on Windows user account. I.e. the encryption key for the file is generated based on the user. How can I do this? Of course, just using the user name is bad, because it should also depend on the users password. Unfortunately I haven't found a function to get the user's password (is there one?). I tried using the System.Security.Cryptography.ProtectedData.Protect function. The problem with this approach is that this function returns a byte array that includes a seed. I.e. when calling this function twice, you'll never get the same results. But this is a requirement, as I want to use its output only as key for my own encryption engine (which offers choice between different algorithms, like AES, Twofish, ...). Best regards Dominik


      Too many passwords to remember? Try KeePass Password Safe!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Using the users name is a bad idea because a user can change their name. You also cannot use a users password because, for one, passwords expire and change, and two, there is no function to get the password. About the only thing that doesn't change in a user object is it's SID.

      Dave Kreskowiak Microsoft MVP - Visual Basic

      D 2 Replies Last reply
      0
      • D Dave Kreskowiak

        Using the users name is a bad idea because a user can change their name. You also cannot use a users password because, for one, passwords expire and change, and two, there is no function to get the password. About the only thing that doesn't change in a user object is it's SID.

        Dave Kreskowiak Microsoft MVP - Visual Basic

        D Offline
        D Offline
        Dominik Reichl
        wrote on last edited by
        #3

        I know that the SID is the only constant thing in a users account, but it is public isn't it? An administrator can easily read all SIDs of users in a network. Therefore, using just the SID is a bad idea, too... Any other way? Thanks for your reply and best regards Dominik


        Too many passwords to remember? Try KeePass Password Safe!

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          Using the users name is a bad idea because a user can change their name. You also cannot use a users password because, for one, passwords expire and change, and two, there is no function to get the password. About the only thing that doesn't change in a user object is it's SID.

          Dave Kreskowiak Microsoft MVP - Visual Basic

          D Offline
          D Offline
          Dominik Reichl
          wrote on last edited by
          #4

          I've just found a solution and wanted to quickly let you know it, in case it's interesting for you, too: First, a random byte array is generated using a cryptographically secure random number generator. This is the key used for encryption. It is protected using ProtectedData.Protect with the DataProtectionScope.CurrentUser option and written to the registry. When loading, the protected key is retrieved from the registry, unprotected using ProtectedData.Unprotect and used as decryption key for our file. I'm not sure what data ProtectedData is using, but it seems that the password can be changed, without making the ProtectedData behavior change, i.e. the user's password actually doesn't matter. Same applies to the user name. Probably Windows keeps some secret key for each user, which we can't access manually. Best regards Dominik


          Too many passwords to remember? Try KeePass Password Safe!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups