Do you always have trouble trying to implement cryptography? Well, you don't need to worry anymore! In this framework I have created a wrapper on top of one of the most beloved crypto frameworks out there, the CryptoSwift.
Why? Just because I wanted to repeat this setup in many projects and then I have created the SecurityService
.
If you are using CocoaPods, add this to your Podfile and run pod install
.
target 'Your target name' do
pod 'SecurityService', '~> 1.0'
end
If you want to add it manually to your project, without a package manager, just copy all files from the Classes
folder to your project.
To create an instance of the service, you only need to import the framework and instantiate the SecurityService
:
import SecurityService
let service = SecurityService()
If you want to have some specific configuration, you can create it like this:
import KeyValueStorage
import SecurityService
service = SecurityService(storage: KeyValueStorage(),
cipherKey: "keykeykeykeykeyk",
cipherIv: "drowssapdrowssap",
hashSalt: "nacllcan",
hashIterations: 4096,
hashKeyLength: 32,
hashVariant: .sha256)
With SecurityService
it is very easy to encrypt/decrypt Data
, it uses the AES-GCM
algorithm and you just need to call it like this:
let source = "some string"
let data = source.data(using: .utf8)!
let encrypted = service.encrypt(data: data)
let decrypted = service.decrypt(data: encrypted!)
let result = String(data: decrypted!, encoding: .utf8)
You can also hash passwords in order to protect the user's data using the PBKDF2
algorithm:
let password = "something"
let hashPassword = service.hash(password: password)
This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See http://www.wassenaar.org/ for more information.
The creation of this framework was possible thanks to these awesome people:
- CryptoSwift: https://github.com/krzyzanowskim/CryptoSwift
- Gray Company: https://www.graycompany.com.br/
- Swift by Sundell: https://www.swiftbysundell.com/
- Hacking with Swift: https://www.hackingwithswift.com/
- Ricardo Rauber: http://ricardorauber.com/
If you notice any issue, got stuck or just want to chat feel free to create an issue. We will be happy to help you.
SecurityService is released under the MIT License.