Git Product home page Git Product logo

ex_windows_api_dataprotection's Introduction

:ex_windows_api_dataprotection

Download on hex.pm/packages/ex_windows_api_dataprotection.

Access the Windows Data Protection API (DPAPI) from Elixir.

The Microsoft Windows Data Protection API (DPAPI) features functions for encrypting/wrapping/protecting and decrypting/unwrapping/unprotecting data, namely CryptProtectData and CryptUnprotectData. These functions are defined in dpapi.h.

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.

The following sample demonstrates it:

import Windows.API.DataProtection, only: [wrap: 1, unwrap: 1]

"Hello world"
|> wrap()
|> unwrap()

returns "Hello world".

Scenario: Why did I create this?

I needed access to the Azure CLI's MSAL token cache, which is in my user directory (%USERPROFILE%\.azure\msal_token_cache.bin).

On Linux and MacOS, this token cache is an un-encrypted JSON file (~/.azure/msal_token_cache.json).

However, on Windows, it's protected / encrypted, using DPAPI. With this module, I can access the JSON contents by unwrapping, with such an Elixir script:

Mix.install([
  {:ex_windows_api_dataprotection, "~> 0.1.2"}
])

[System.user_home!(), ".azure", "msal_token_cache.bin"]
|> Path.join
|> File.read!()
|> Windows.API.DataProtection.unwrap()
|> IO.puts()

Marketing ๐Ÿ˜œ

Thanks to @brainlid, @dbern-stripe, and @cadebward for featuring this little library in the "Thinking Elixir podcast / Magic Links episode 184, starting at minute 4:04...

ex_windows_api_dataprotection's People

Contributors

chgeuer avatar

Watchers

 avatar

ex_windows_api_dataprotection's Issues

Create an empty Linux implementation of the crate `"x86_64-unknown-linux-gnu"`

Resolving Hex dependencies...
Resolution completed in 0.099s
New:
  castore 1.0.5
  ex_windows_api_dataprotection 0.1.1
  rustler_precompiled 0.7.1
* Getting ex_windows_api_dataprotection (Hex package)
* Getting rustler_precompiled (Hex package)
* Getting castore (Hex package)

== Compilation error in file lib/internal/native.ex ==
** (RuntimeError) precompiled NIF is not available for this target: "x86_64-unknown-linux-gnu".
The available targets are:
 - x86_64-pc-windows-msvc
 - x86_64-pc-windows-gnu
    lib/internal/native.ex:13: (module)

could not compile dependency :ex_windows_api_dataprotection, "mix compile" failed. 

Errors may have been logged above. 

You can recompile this dependency with "mix deps.compile ex_windows_api_dataprotection --force", 
update it with "mix deps.update ex_windows_api_dataprotection" or 
clean it with "mix deps.clean ex_windows_api_dataprotection"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.