Method: Axlsx::MsOffCrypto#create_encryption_info

Defined in:
lib/axlsx/util/ms_off_crypto.rb

#create_encryption_infoString

Generates an encryption info structure

Returns:

  • (String)


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/axlsx/util/ms_off_crypto.rb', line 105

def create_encryption_info
  header = [3, 0, 2, 0] # version
  # Header flags copy
  header.concat [0x24, 0, 0, 0] #flags -- VERY UNSURE ABOUT THIS STILL
  # header.concat [0, 0, 0, 0] #unused
  header.concat [0xA4, 0, 0, 0] #length
  # Header
  header.concat  [0x24, 0, 0, 0] #flags again
  # header.concat [0, 0, 0, 0] #unused again,
  header.concat [0x0E, 0x66, 0, 0] #alg id
  header.concat [0x04, 0x80, 0, 0] #alg hash id
  header.concat [key.size, 0, 0, 0] #key size
  header.concat [0x18, 0, 0, 0] #provider type
  # header.concat [0, 0, 0, 0] #reserved 1
  # header.concat [0, 0, 0, 0] #reserved 2
  header.concat [0xA0, 0xC7, 0xDC, 0x2, 0, 0, 0, 0]
  header.concat "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)".bytes.to_a.pack('s*').bytes.to_a
  header.concat [0, 0] #null terminator

  #Salt Size
  header.concat [salt.bytes.to_a.size].pack('l').bytes.to_a
  #Salt
  header.concat salt.bytes.to_a.pack('c*').bytes.to_a
  # encryption verifier
  header.concat encrypted_verifier.bytes.to_a.pack('c*').bytes.to_a

  # verifier hash size -- MUST BE 32 bytes
  header.concat [verifier_hash.bytes.to_a.size].pack('l').bytes.to_a

  #encryption verifier hash
  header.concat encrypted_verifier_hash.bytes.to_a.pack('c*').bytes.to_a

  header.flatten!
  header.pack('c*')
end