https://github.com/dracoon/dracoon-swift-crypto-sdk
Official DRACOON Crypto SDK for Swift
https://github.com/dracoon/dracoon-swift-crypto-sdk
crypto cryptography dracoon sdk swift
Last synced: 4 months ago
JSON representation
Official DRACOON Crypto SDK for Swift
- Host: GitHub
- URL: https://github.com/dracoon/dracoon-swift-crypto-sdk
- Owner: dracoon
- License: other
- Created: 2018-04-04T13:47:25.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2025-01-07T12:47:25.000Z (over 1 year ago)
- Last Synced: 2025-06-11T10:17:46.639Z (about 1 year ago)
- Topics: crypto, cryptography, dracoon, sdk, swift
- Language: Swift
- Homepage:
- Size: 93.1 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Support: Supporting Files/Info.plist
Awesome Lists containing this project
README
# DRACOON Swift Crypto SDK
A library which implements the client-side encryption of DRACOON.
# Introduction
A detailed description of client-side encryption of DRACOON can be found here:
https://support.dracoon.com/hc/en-us/articles/360000986345
# Setup
#### Swift Package Manager
Add this line to the dependencies section of your Package.swift:
`.package(url: "https://github.com/dracoon/dracoon-swift-crypto-sdk", .upToNextMajor(from: "3.0.0"))`
If you need to define the SDK as target dependency add it like this:
```
targets: [
...
.target(
dependencies: [
.product(name: "crypto_sdk", package: "dracoon-swift-crypto-sdk")
]
...
)
]
```
#### Carthage
Add the SDK to your Cartfile:
`github "dracoon/dracoon-swift-crypto-sdk.git" ~> 3.0.0`
Then run
`carthage update --use-xcframeworks --platform iOS`
to create an xcframework.
#### CocoaPods
Add to your Podfile:
```
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '15.0'
use_frameworks!
target '' do
pod 'DRACOON-Crypto-SDK', '~> v3.0.0'
end
```
Then run
`pod install`
# Example
An example playground can be found here: `Example/CryptoSDK.playground`
The example shows the complete encryption workflow, i.e. generate user keypair, validate user
keypair, generate file key, encrypt file key, and finally encrypt and decrypt a file.
```swift
// --- INITIALIZATION ---
let crypto = Crypto()
// Generate key pair
let userKeyPair = try crypto.generateUserKeyPair(password: USER_PASSWORD)
// Check key pair
if !crypto.checkUserKeyPair(keyPair: userKeyPair, password: USER_PASSWORD) {
...
}
let plainData = plainText.data(using: .utf8)
...
// --- ENCRYPTION ---
// Generate plain file key
let plainFileKey = try crypto.generateFileKey()
// Encrypt blocks
let encryptionCipher = try crypto.createEncryptionCipher(fileKey: fileKey)
let encData = try encryptionCipher.processBlock(fileData: plainData)
try encryptionCipher.doFinal()
// Encrypt file key
let encryptedKey = try crypto.encryptFileKey(fileKey: plainFileKey, publicKey: userKeyPair.publicKeyContainer)
...
// --- DECRYPTION ---
// Decrypt file key
let decryptedKey = try crypto.decryptFileKey(fileKey: encryptedKey, privateKey: userKeyPair.privateKeyContainer,
USER_PASSWORD)
// Decrypt blocks
let decryptionCipher = try crypto.createDecryptionCipher(fileKey: fileKey)
let decData = try decryptionCipher.processBlock(fileData: encData)
try decryptionCipher.doFinal()
...
```
#### Build boringSSL
If you want to update the crypto library, please adjust and run
`./build-boringssl.sh`
Then copy the content from output dir to the 'OpenSSL' directory.
# Copyright and License
See [LICENSE](LICENSE)