{"id":20626441,"url":"https://github.com/chgeuer/windows-dpapi-with-zig","last_synced_at":"2026-04-21T01:31:05.013Z","repository":{"id":213370773,"uuid":"733926352","full_name":"chgeuer/Windows-DPAPI-with-Zig","owner":"chgeuer","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-23T11:07:01.000Z","size":127,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T04:27:01.114Z","etag":null,"topics":["dataprotection","dpapi","windows","zig","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"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":null,"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-20T12:57:42.000Z","updated_at":"2023-12-23T22:13:57.000Z","dependencies_parsed_at":"2023-12-20T17:14:46.650Z","dependency_job_id":"22708758-822f-4363-be46-f34007112b2f","html_url":"https://github.com/chgeuer/Windows-DPAPI-with-Zig","commit_stats":null,"previous_names":["chgeuer/windows-dpapi-with-zig"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chgeuer/Windows-DPAPI-with-Zig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgeuer%2FWindows-DPAPI-with-Zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgeuer%2FWindows-DPAPI-with-Zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgeuer%2FWindows-DPAPI-with-Zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgeuer%2FWindows-DPAPI-with-Zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chgeuer","download_url":"https://codeload.github.com/chgeuer/Windows-DPAPI-with-Zig/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgeuer%2FWindows-DPAPI-with-Zig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32072953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T21:26:33.338Z","status":"ssl_error","status_checked_at":"2026-04-20T21:26:22.081Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dataprotection","dpapi","windows","zig","ziglang"],"created_at":"2024-11-16T13:13:16.219Z","updated_at":"2026-04-21T01:31:04.998Z","avatar_url":"https://github.com/chgeuer.png","language":"Zig","readme":"# Exploring the Windows Data Protection API (DPAPI) from [Zig](https://ziglang.org/)\n\nThis project features a little command line utility which reads encrypted data from stdin and writes to stdout.\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## Compiling and running\n\nThe following command compiles a small CLI application (18kB on Windows):\n\n```shell\nzig build -Doptimize=ReleaseSmall\n```\n\nThen you pipe the contents of an encrypted file into the executable, and process the output like you wish. For example, on Windows, the Azure CLI stores all management tokens as JSON structure in an encrypted file in my `.azure` directory. The following pipeline pipes that file into the decryption utility and uses [JQ](https://jqlang.github.io/jq/) to pretty-print parts of the JSON.\n\n```shell\ntype %USERPROFILE%\\.azure\\msal_token_cache.bin | .\\zig-out\\bin\\dpapi.exe unwrap  | jq.exe \".RefreshToken\"\n```\n\nWith the checked-in binaries, you can also do round-trip:\n\n```shell\necho Hallo Welt | .\\dpapi.exe wrap | .\\dpapi.exe unwrap\n```\n\ngives\n\n```\nC:\\github\\chgeuer\\Windows-DPAPI-with-Zig (main -\u003e origin)\nλ echo Hallo Welt | .\\dpapi.exe wrap | .\\dpapi.exe unwrap\n\nHallo Welt\n\nC:\\github\\chgeuer\\Windows-DPAPI-with-Zig (main -\u003e origin)\nλ \n```\n\n## Alternative in NET\n\nThe C# version would be along these lines (using `System.Security.dll`):\n\n```csharp\nusing System;\nusing System.Security.Cryptography;\nusing System.Text;\nusing System.IO;\n\ninternal class Program\n{\n    static void Main(string[] args)\n    {\n        var input = \"Hallo, Welt!\";\n        byte[] wrapped = Encrypt(input);\n        File.WriteAllBytes(@\"C:\\Users\\chgeuer\\Desktop\\zig2\\dpapi_encrypted.bin\", wrapped);\n\n        Console.WriteLine(Convert.ToBase64String(wrapped));\n        Console.WriteLine(Decrypt(wrapped));\n    }\n\n    private static byte[] Encrypt(string userData) =\u003e\n        ProtectedData.Protect(\n            userData: Encoding.UTF8.GetBytes(userData),\n            optionalEntropy: null,\n            scope: DataProtectionScope.CurrentUser);\n\n    private static string Decrypt(byte[] wrapped) =\u003e\n        Encoding.UTF8.GetString(\n            ProtectedData.Unprotect(\n                encryptedData: wrapped,\n                optionalEntropy: null, \n                scope: DataProtectionScope.CurrentUser));\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchgeuer%2Fwindows-dpapi-with-zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchgeuer%2Fwindows-dpapi-with-zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchgeuer%2Fwindows-dpapi-with-zig/lists"}