Class: OoxmlDecrypt::EncryptedFile
- Inherits:
-
Object
- Object
- OoxmlDecrypt::EncryptedFile
- Defined in:
- lib/ooxml_decrypt/encrypted_file.rb
Class Method Summary collapse
-
.decrypt(filename, password) ⇒ Object
Decrypts the given file using the given password.
-
.decrypt_to_file(enc_filename, password, dec_filename) ⇒ Object
Decrypts the given file using the given password and writes the result to a second file.
Instance Method Summary collapse
-
#decrypt(password) ⇒ String
Decrypts this encrypted file using the given password.
-
#initialize(filename) ⇒ EncryptedFile
constructor
A new instance of EncryptedFile.
Constructor Details
#initialize(filename) ⇒ EncryptedFile
Returns a new instance of EncryptedFile.
7 8 9 10 11 12 13 |
# File 'lib/ooxml_decrypt/encrypted_file.rb', line 7 def initialize(filename) @ole = Ole::Storage.open(filename) unless @ole.dir.entries(".").include?("EncryptionInfo") and @ole.dir.entries(".").include?("EncryptedPackage") raise "File does not appear to be an encrypted Office document" end end |
Class Method Details
.decrypt(filename, password) ⇒ Object
Decrypts the given file using the given password
71 72 73 74 |
# File 'lib/ooxml_decrypt/encrypted_file.rb', line 71 def self.decrypt(filename, password) encrypted_file = EncryptedFile.new(filename) return encrypted_file.decrypt(password) end |
.decrypt_to_file(enc_filename, password, dec_filename) ⇒ Object
Decrypts the given file using the given password and writes the result to a second file
83 84 85 86 |
# File 'lib/ooxml_decrypt/encrypted_file.rb', line 83 def self.decrypt_to_file(enc_filename, password, dec_filename) plaintext = decrypt(enc_filename, password) File.open(dec_filename, "wb") {|file| file.write(plaintext)} end |
Instance Method Details
#decrypt(password) ⇒ String
Decrypts this encrypted file using the given password
62 63 64 65 |
# File 'lib/ooxml_decrypt/encrypted_file.rb', line 62 def decrypt(password) decryption_key = encrypted_key.key(password) return key_data.decrypt_encrypted_package_stream( encrypted_package, decryption_key ) end |