Contents.swift 1006 B

1234567891011121314151617181920212223242526272829303132
  1. /*:
  2. To whom may be concerned: I offer professional support to all my open source projects.
  3. Contact: [marcin@krzyzanowskim.com](http://krzyzanowskim.com)
  4. */
  5. import CryptoSwift
  6. //: # AES
  7. //: One-time shot
  8. do {
  9. let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap")
  10. let ciphertext = try aes.encrypt("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8.map({$0}))
  11. print(ciphertext.toHexString())
  12. } catch {
  13. print(error)
  14. }
  15. //: Incremental encryption
  16. do {
  17. let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap")
  18. var encryptor = aes.makeEncryptor()
  19. var ciphertext = Array<UInt8>()
  20. ciphertext += try encryptor.update(withBytes: "Nullam quis risus ".utf8.map({$0}))
  21. ciphertext += try encryptor.update(withBytes: "eget urna mollis ".utf8.map({$0}))
  22. ciphertext += try encryptor.update(withBytes: "ornare vel eu leo.".utf8.map({$0}))
  23. ciphertext += try encryptor.finish()
  24. print(ciphertext.toHexString())
  25. } catch {
  26. print(error)
  27. }