Class: ReservedNames::Win32::Crypto

Inherits:
Object
  • Object
show all
Extended by:
Chef::ReservedNames::Win32::API::Crypto
Includes:
Chef::ReservedNames::Win32::API::Crypto
Defined in:
lib/chef/win32/crypto.rb

Constant Summary

Constants included from Chef::ReservedNames::Win32::API::Crypto

Chef::ReservedNames::Win32::API::Crypto::CRYPTPROTECT_AUDIT, Chef::ReservedNames::Win32::API::Crypto::CRYPTPROTECT_LOCAL_MACHINE, Chef::ReservedNames::Win32::API::Crypto::CRYPTPROTECT_UI_FORBIDDEN

Class Method Summary collapse

Class Method Details

.encrypt(str, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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