{"id":20626435,"url":"https://github.com/chgeuer/ex_windows_api_dataprotection","last_synced_at":"2025-03-08T00:36:02.226Z","repository":{"id":213822221,"uuid":"735013653","full_name":"chgeuer/ex_windows_api_dataprotection","owner":"chgeuer","description":"Access the Windows Data Protection API (DPAPI) from Elixir","archived":false,"fork":false,"pushed_at":"2024-01-28T15:32:58.000Z","size":42,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T09:15:40.589Z","etag":null,"topics":["dpapi","elixir","rust-lang","rustler","windows"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/ex_windows_api_dataprotection","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chgeuer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-23T11:02:02.000Z","updated_at":"2023-12-23T22:12:23.000Z","dependencies_parsed_at":"2023-12-23T12:32:43.382Z","dependency_job_id":"f24d2217-bc70-406b-9df4-75d7da307e1d","html_url":"https://github.com/chgeuer/ex_windows_api_dataprotection","commit_stats":{"total_commits":35,"total_committers":1,"mean_commits":35.0,"dds":0.0,"last_synced_commit":"eec530d6baa77f7e07f1c187e6df61ea9f41eb70"},"previous_names":["chgeuer/ex_windows_api_dataprotection"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgeuer%2Fex_windows_api_dataprotection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgeuer%2Fex_windows_api_dataprotection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgeuer%2Fex_windows_api_dataprotection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgeuer%2Fex_windows_api_dataprotection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chgeuer","download_url":"https://codeload.github.com/chgeuer/ex_windows_api_dataprotection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242483345,"owners_count":20135784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dpapi","elixir","rust-lang","rustler","windows"],"created_at":"2024-11-16T13:13:14.872Z","updated_at":"2025-03-08T00:36:02.209Z","avatar_url":"https://github.com/chgeuer.png","language":"Elixir","readme":"# :ex_windows_api_dataprotection\n\nDownload on [hex.pm/packages/ex_windows_api_dataprotection](https://hex.pm/packages/ex_windows_api_dataprotection).\n\n\u003e Access the Windows Data Protection API (DPAPI) from Elixir. \n\nThe [Microsoft Windows Data Protection API (DPAPI)](https://learn.microsoft.com/en-us/windows/win32/api/dpapi/) features functions for encrypting/wrapping/protecting and decrypting/unwrapping/unprotecting data, namely [CryptProtectData](https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata) and [CryptUnprotectData](https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptunprotectdata). These functions are defined in `dpapi.h`. \n\n\u003e The DPAPI on Windows is similar to other mechanisms, such as KeyChain on MacOS. The difference certainly is that DPAPI only takes care of encryption/decryption, and the user supplies the plaintext or ciphertext. Under the hood, Windows stores key material in the Windows registry, so that only *the currently logged-in user*, *on the current machine*, can decrypt the data encrypted by that user on that machine.\n\nThe following sample demonstrates it:\n\n```elixir\nimport Windows.API.DataProtection, only: [wrap: 1, unwrap: 1]\n\n\"Hello world\"\n|\u003e wrap()\n|\u003e unwrap()\n```\n\nreturns `\"Hello world\"`.\n\n## Scenario: Why did I create this?\n\nI needed access to the [Azure CLI's MSAL token cache](https://learn.microsoft.com/en-us/cli/azure/msal-based-azure-cli), which is in my user directory (`%USERPROFILE%\\.azure\\msal_token_cache.bin`). \n\nOn Linux and MacOS, this token cache is an un-encrypted JSON file (`~/.azure/msal_token_cache.json`).\n\nHowever, on Windows, it's protected / encrypted, using DPAPI. With this module, I can access the JSON contents by unwrapping, with such an Elixir script:\n\n```elixir\nMix.install([\n  {:ex_windows_api_dataprotection, \"~\u003e 0.1.2\"}\n])\n\n[System.user_home!(), \".azure\", \"msal_token_cache.bin\"]\n|\u003e Path.join\n|\u003e File.read!()\n|\u003e Windows.API.DataProtection.unwrap()\n|\u003e IO.puts()\n```\n\n## Marketing 😜\n\nThanks to @brainlid, @dbern-stripe, and @cadebward for featuring this little library in the [\"Thinking Elixir podcast / Magic Links episode 184](https://podcast.thinkingelixir.com/184), starting at minute 4:04...\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchgeuer%2Fex_windows_api_dataprotection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchgeuer%2Fex_windows_api_dataprotection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchgeuer%2Fex_windows_api_dataprotection/lists"}