Skip to content

Instantly share code, notes, and snippets.

@thomsh
Created July 15, 2020 09:41
Show Gist options
  • Save thomsh/4f33a90bacb155fbba78d1be8b0d954c to your computer and use it in GitHub Desktop.
Save thomsh/4f33a90bacb155fbba78d1be8b0d954c to your computer and use it in GitHub Desktop.

Revisions

  1. thomsh created this gist Jul 15, 2020.
    16 changes: 16 additions & 0 deletions decrypt_databag.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/opt/chef-workstation/embedded/bin/ruby
    require "chef/encrypted_data_bag_item"
    require "json"

    if ARGV.length != 2
    puts "usage: decrypt_databag.rb /path/to/cipher_json_data_bag KEY"
    abort
    end

    cipherdata_path = ARGV[0]
    secret = ARGV[1]

    #secret = Chef::EncryptedDataBagItem.load_secret(ARGV[1])
    encrypted_data = JSON.parse(File.read(cipherdata_path))
    plain_data = Chef::EncryptedDataBagItem.new(encrypted_data, secret).to_hash
    puts JSON.pretty_generate(plain_data)