فهرست منبع

Playground with AES

Marcin Krzyżanowski 9 سال پیش
والد
کامیت
5c01fcf817
2فایلهای تغییر یافته به همراه31 افزوده شده و 1 حذف شده
  1. 30 0
      CryptoSwift.playground/Contents.swift
  2. 1 1
      CryptoSwift.playground/contents.xcplayground

+ 30 - 0
CryptoSwift.playground/Contents.swift

@@ -1,2 +1,32 @@
+/*:
+ To whom may be concerned: I offer professional support to all my open source projects.
+ 
+ Contact: [marcin@krzyzanowskim.com](http://krzyzanowskim.com)
+*/
 import CryptoSwift
 
+//: # AES
+//: One-time shot
+do {
+    let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap")
+    let ciphertext = try aes.encrypt("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8.map({$0}))
+    print(ciphertext.toHexString())
+} catch {
+    print(error)
+}
+
+//: Incremental encryption
+do {
+    let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap")
+    var encryptor = aes.makeEncryptor()
+
+    var ciphertext = Array<UInt8>()
+    ciphertext += try encryptor.update(withBytes: "Nullam quis risus ".utf8.map({$0}))
+    ciphertext += try encryptor.update(withBytes: "eget urna mollis ".utf8.map({$0}))
+    ciphertext += try encryptor.update(withBytes: "ornare vel eu leo.".utf8.map({$0}))
+    ciphertext += try encryptor.finish()
+
+    print(ciphertext.toHexString())
+} catch {
+    print(error)
+}

+ 1 - 1
CryptoSwift.playground/contents.xcplayground

@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<playground version='5.0' target-platform='ios'>
+<playground version='5.0' target-platform='ios' display-mode='raw'>
     <timeline fileName='timeline.xctimeline'/>
 </playground>