|
@@ -189,7 +189,7 @@ let hex = bytes.toHexString() // "010203"
|
|
|
|
|
|
Build bytes out of `String`
|
|
Build bytes out of `String`
|
|
```swift
|
|
```swift
|
|
-let bytes = "string".utf8.map({$0})
|
|
|
|
|
|
+let bytes = Array("string".utf8)
|
|
```
|
|
```
|
|
|
|
|
|
Also... check out helpers that work with **Base64** encoded data:
|
|
Also... check out helpers that work with **Base64** encoded data:
|
|
@@ -257,10 +257,8 @@ try HMAC(key: key, variant: .sha256).authenticate(bytes)
|
|
#####Password-Based Key Derivation Functions
|
|
#####Password-Based Key Derivation Functions
|
|
|
|
|
|
```swift
|
|
```swift
|
|
-let password: Array<UInt8> = "s33krit".utf8.map {$0}
|
|
|
|
-let salt: Array<UInt8> = "nacllcan".utf8.map {$0}
|
|
|
|
-
|
|
|
|
-try PKCS5.PBKDF1(password: password, salt: salt, variant: .sha1, iterations: 4096).calculate()
|
|
|
|
|
|
+let password: Array<UInt8> = Array("s33krit".utf8)
|
|
|
|
+let salt: Array<UInt8> = Array("nacllcan".utf8)
|
|
|
|
|
|
try PKCS5.PBKDF2(password: password, salt: salt, iterations: 4096, variant: .sha256).calculate()
|
|
try PKCS5.PBKDF2(password: password, salt: salt, iterations: 4096, variant: .sha256).calculate()
|
|
```
|
|
```
|
|
@@ -313,7 +311,7 @@ try AES(key: [1,2,3,...,32], iv: [1,2,3,...,16], blockMode: .CBC, padding: PKCS7
|
|
```swift
|
|
```swift
|
|
do {
|
|
do {
|
|
let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap") // aes128
|
|
let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap") // aes128
|
|
- let ciphertext = try aes.encrypt("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8.map({$0}))
|
|
|
|
|
|
+ let ciphertext = try aes.encrypt(Array("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8))
|
|
} catch { }
|
|
} catch { }
|
|
```
|
|
```
|
|
|
|
|
|
@@ -327,9 +325,9 @@ do {
|
|
|
|
|
|
var ciphertext = Array<UInt8>()
|
|
var ciphertext = Array<UInt8>()
|
|
// aggregate partial results
|
|
// aggregate partial results
|
|
- 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.update(withBytes: Array("Nullam quis risus ".utf8))
|
|
|
|
+ ciphertext += try encryptor.update(withBytes: Array("eget urna mollis ".utf8))
|
|
|
|
+ ciphertext += try encryptor.update(withBytes: Array("ornare vel eu leo.".utf8))
|
|
// finish at the end
|
|
// finish at the end
|
|
ciphertext += try encryptor.finish()
|
|
ciphertext += try encryptor.finish()
|
|
|
|
|