class Chef::ReservedNames::Win32::Crypto

Public Class Methods

encrypt(str, &block) click to toggle source
# File lib/chef/win32/crypto.rb, line 31
def self.encrypt(str, &block)
  data_blob = CRYPT_INTEGER_BLOB.new
  unless CryptProtectData(CRYPT_INTEGER_BLOB.new(str.to_wstring), nil, nil, nil, nil, CRYPTPROTECT_LOCAL_MACHINE, data_blob)
    Chef::ReservedNames::Win32::Error.raise!
  end
  bytes = data_blob[:pbData].get_bytes(0, data_blob[:cbData])
  if block
    block.call(bytes)
  else
    Digest.hexencode(bytes)
  end
ensure
  unless data_blob[:pbData].null?
    Chef::ReservedNames::Win32::Memory.local_free(data_blob[:pbData])
  end
end