CryptoOffice is a library for decrypting Microsoft Office formats that utilise ECMA-376 agile encryption. It should be used in conjuction with libraries that allow parsing decrypted data, such as CoreXLSX.
Join our Discord for any questions and friendly banter.
Using CryptoOffice is easy:
- Add
import CryptoOffice
at the top of a relevant Swift source file. - Use
CryptoOfficeFile(path: String)
to create a new instance with a path to your encrypted file. - Call
decrypt(password: String)
on it to get decrypted data. - Parse the decrypted data with a library appropriate for that format (CoreXLSX in this example).
import CoreXLSX
import CryptoOffice
let encryptedFile = try CryptoOfficeFile(path: "./categories.xlsx")
let decryptedData = try encryptedFile.decrypt(password: "pass")
let xlsx = try XLSXFile(data: decryptedData)
for path in try xlsx.parseWorksheetPaths() {
let worksheet = try xlsx.parseWorksheet(at: path)
for row in worksheet.data?.rows ?? [] {
for c in row.cells {
print(c)
}
}
}
Apple Platforms
- Xcode 12.4 or later
- Swift 5.3 or later
- iOS 13.0 / watchOS 6.0 / tvOS 13.0 / macOS 10.15 or later deployment targets
Linux
- Swift 5.3 or later
Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies on all platforms.
Once you have your Swift package set up, adding CryptoOffice
as a dependency is as
easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/CoreOffice/CryptoOffice.git",
.upToNextMinor(from: "0.1.1"))
]
If you're using CryptoOffice in an app built with Xcode, you can also add it as a direct dependency using Xcode's GUI.
This project uses SwiftFormat and SwiftLint to enforce formatting and coding style. We encourage you to run SwiftFormat within a local clone of the repository in whatever way works best for you either manually or automatically via an Xcode extension, build phase or git pre-commit hook etc.
To guarantee that these tools run before you commit your changes on macOS, you're encouraged to run this once to set up the pre-commit hook:
brew bundle # installs SwiftLint, SwiftFormat and pre-commit
pre-commit install # installs pre-commit hook to run checks before you commit
Refer to the pre-commit documentation page for more details and installation instructions for other platforms.
SwiftFormat and SwiftLint also run on CI for every PR and thus a CI build can fail with incosistent formatting or style. We require CI builds to pass for all PRs before merging.
This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to coreoffice@desiatov.com.
CryptoOffice is licensed under the Apache License, Version 2.0 (the "License"); you may not use this library except in compliance with the License. See the LICENSE file for more info.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
CryptoOffice uses swift-crypto, CryptoSwift, XMLCoder, OLEKit and ZIPFoundation. The latter is only a dependency of CryptoOffice's test suite. Please check the respective projects for their actual licensing information.