2020-06-30 14:41:58 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
CommonCrypto library:
|
2020-06-30 14:41:58 +02:00
|
|
|
|
|
|
|
----
|
2020-12-21 15:38:52 +01:00
|
|
|
import CommonCrypto
|
2020-06-30 14:41:58 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
let algorithm = CCAlgorithm(kCCAlgorithmDES) // Noncompliant: 64 bits block size
|
|
|
|
----
|
2020-06-30 14:41:58 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
https://github.com/iosdevzone/IDZSwiftCommonCrypto[IDZSwiftCommonCrypto] library:
|
2020-06-30 14:41:58 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
----
|
|
|
|
import IDZSwiftCommonCrypto
|
2020-06-30 14:41:58 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
let algorithm = .des // Noncompliant: 64 bits block size
|
2020-06-30 14:41:58 +02:00
|
|
|
----
|
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
https://github.com/krzyzanowskim/CryptoSwift[CryptoSwift]
|
2020-06-30 14:41:58 +02:00
|
|
|
|
|
|
|
----
|
2020-12-21 15:38:52 +01:00
|
|
|
import CryptoSwift
|
|
|
|
|
|
|
|
let blowfish = try Blowfish(key: key, blockMode: GCM(iv: iv, mode: .combined), padding: .pkcs7) // Noncompliant: 64 bits block size
|
2020-06-30 14:41:58 +02:00
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
https://swift.org/blog/crypto/[Swift Crypto] library: prefer using this library which is native and officially supported by Apple
|
|
|
|
|
|
|
|
----
|
|
|
|
import Crypto
|
|
|
|
|
|
|
|
let sealedBox = try AES.GCM.seal(input, using: key) // Compliant
|
|
|
|
----
|
|
|
|
|
|
|
|
CommonCrypto library:
|
2020-06-30 14:41:58 +02:00
|
|
|
|
|
|
|
----
|
2020-12-21 15:38:52 +01:00
|
|
|
import CommonCrypto
|
2020-06-30 14:41:58 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
let algorithm = CCAlgorithm(kCCAlgorithmAES) // Compliant
|
2020-06-30 14:41:58 +02:00
|
|
|
----
|
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
https://github.com/iosdevzone/IDZSwiftCommonCrypto[IDZSwiftCommonCrypto] library:
|
|
|
|
|
|
|
|
----
|
|
|
|
import IDZSwiftCommonCrypto
|
2020-06-30 14:41:58 +02:00
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
let algorithm = .aes // Compliant
|
2020-06-30 14:41:58 +02:00
|
|
|
----
|
2020-12-21 15:38:52 +01:00
|
|
|
|
|
|
|
https://github.com/krzyzanowskim/CryptoSwift[CryptoSwift]
|
|
|
|
|
|
|
|
----
|
|
|
|
import CryptoSwift
|
|
|
|
|
|
|
|
let aes = try AES(key: key, iv: iv) // Compliant
|
2020-06-30 14:41:58 +02:00
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
|
|
|
ifdef::rspecator-view[]
|
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::rspecator-view[]
|