-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,674 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
|
||
# Created by https://www.gitignore.io/api/macos,swift,xcode | ||
# Edit at https://www.gitignore.io/?templates=macos,swift,xcode | ||
|
||
### macOS ### | ||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### Swift ### | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
build/ | ||
DerivedData/ | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata/ | ||
|
||
## Other | ||
*.moved-aside | ||
*.xccheckout | ||
*.xcscmblueprint | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
# Package.pins | ||
# Package.resolved | ||
.build/ | ||
|
||
# CocoaPods | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# Pods/ | ||
# Add this line if you want to avoid checking in source code from the Xcode workspace | ||
# *.xcworkspace | ||
|
||
# Carthage | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build | ||
|
||
# fastlane | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
|
||
# Code Injection | ||
# After new code Injection tools there's a generated folder /iOSInjectionProject | ||
# https://github.com/johnno1962/injectionforxcode | ||
|
||
iOSInjectionProject/ | ||
|
||
### Xcode ### | ||
# Xcode | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## User settings | ||
|
||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) | ||
|
||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) | ||
|
||
### Xcode Patch ### | ||
*.xcodeproj/* | ||
!*.xcodeproj/project.pbxproj | ||
!*.xcodeproj/xcshareddata/ | ||
!*.xcworkspace/contents.xcworkspacedata | ||
/*.gcno | ||
**/xcshareddata/WorkspaceSettings.xcsettings | ||
|
||
# End of https://www.gitignore.io/api/macos,swift,xcode |
16 changes: 16 additions & 0 deletions
16
...aphy & Privacy.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Manifest.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Name</key> | ||
<string>Chapter 1</string> | ||
<key>Pages</key> | ||
<array> | ||
<string>Introduction.cutscenepage</string> | ||
<string>Cryptography Foundation.playgroundpage</string> | ||
<string>Symmetric-Key Cryptography.playgroundpage</string> | ||
<string>Asymmetric-Key Cryptography.playgroundpage</string> | ||
<string>Practice.playgroundpage</string> | ||
</array> | ||
</dict> | ||
</plist> |
80 changes: 80 additions & 0 deletions
80
...hapter1.playgroundchapter/Pages/Asymmetric-Key Cryptography.playgroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//#-hidden-code | ||
// | ||
// See LICENSE folder for this template’s licensing information. | ||
// | ||
// Abstract: | ||
// The Swift file containing the source code edited by the user of this playground book. | ||
// | ||
|
||
import Foundation | ||
import PlaygroundSupport | ||
//#-end-hidden-code | ||
/*: | ||
# Asymmetric-Key Cryptography | ||
In asymmetric-key cryptography, we use a key-pair which contains a public key and a private key. After generating a key-pair, we usually send the public one to others, and keep the private one on the disk. As a result, anyone holding your public key can use it to send encrypted messages to you, and it can only be decrypted using the corresponding private key. | ||
This is to say, the sender doesn't need to know how to decrypt the content when encrypting, which solves the key distribution problem. | ||
> Use `generateKeyPair()` to generate a key-pair (this may take a while) | ||
> | ||
> Use `encrypt(contentData: , usingPublicKey: )` and `decrypt(contentData: , usingPrivateKey: )` to encrypt/decrypt | ||
> | ||
> For detailed usage, see help of each function | ||
- Example: | ||
``` | ||
let keyPair = generateKeyPair() | ||
let text = "TOP SECRET" | ||
let textData = text.data(using: .utf8)! | ||
let encrypted = encrypt(contentData: textData, usingPublicKey: keyPair.publicKey) | ||
let decrypted = decrypt(contentData: encrypted, usingPrivateKey: keyPair.privateKey) | ||
print(String(data: decrypted, encoding: .utf8)!) | ||
// Output: "TOP SECRET" | ||
``` | ||
- Important: | ||
Encrypting/Decrypting using asymmetric-key cryptography can be **way slower** than symmetric-key cryptography, and therefore is **not suitable for large files**. | ||
*/ | ||
|
||
// Encrypt the text using a designated public key | ||
func encrypt(text: String, usingPublicKey publicKey: SecKey) -> Data { | ||
let textData = text.data(using: .utf8)! | ||
return encrypt(contentData: /*#-editable-code*/<#T##Plain Data##Data#>/*#-end-editable-code*/ | ||
, usingPublicKey: /*#-editable-code*/<#T##Public Key##SecKey#>/*#-end-editable-code*/ | ||
) | ||
} | ||
|
||
// Decrypt the text using a designated private key | ||
func decrypt(encryptedData: Data, usingPrivateKey privateKey: SecKey) -> String { | ||
let decrypted = decrypt(contentData: /*#-editable-code*/<#T##Encrypted Data##Data#>/*#-end-editable-code*/, usingPrivateKey: /*#-editable-code*/<#T##Private Key##SecKey#>/*#-end-editable-code*/) | ||
return String(data: decrypted, encoding: .utf8)! | ||
} | ||
|
||
//#-hidden-code | ||
let keyPair = generateKeyPair() | ||
let randomContent = generateRandomContent() | ||
let encrypted = encrypt(text: randomContent, usingPublicKey: keyPair.publicKey) | ||
let decrypted = decrypt(encryptedData: encrypted, usingPrivateKey: keyPair.privateKey) | ||
if decrypted == randomContent { | ||
PlaygroundPage.current.assessmentStatus = .pass(message: """ | ||
Congratulations, You've learnt how to use asymmetric-key cryptography! | ||
[Cryptography & Privacy in Practice: Secure Chat](@next) | ||
""") | ||
} else { | ||
PlaygroundPage.current.assessmentStatus = .fail(hints: ["Please read the text above again to ensure you understand how to use asymmetric cryptography."], solution: """ | ||
``` | ||
func encrypt(text: String, usingPublicKey publicKey: SecKey) -> Data { | ||
let textData = text.data(using: .utf8)! | ||
return encrypt(contentData: textData, usingPublicKey: publicKey) | ||
} | ||
func decrypt(encryptedData: Data, usingPrivateKey privateKey: SecKey) -> String { | ||
let decrypted = decrypt(contentData: encryptedData, usingPrivateKey: privateKey) | ||
return String(data: decrypted, encoding: .utf8)! | ||
} | ||
``` | ||
""") | ||
|
||
} | ||
//#-end-hidden-code |
12 changes: 12 additions & 0 deletions
12
...hapter1.playgroundchapter/Pages/Asymmetric-Key Cryptography.playgroundpage/LiveView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// See LICENSE folder for this template’s licensing information. | ||
// | ||
// Abstract: | ||
// Instantiates a live view and passes it to the PlaygroundSupport framework. | ||
// | ||
|
||
import UIKit | ||
import PlaygroundSupport | ||
|
||
// Instantiate a new instance of the live view from the book's auxiliary sources and pass it to PlaygroundSupport. | ||
PlaygroundPage.current.liveView = instantiateLiveView() |
12 changes: 12 additions & 0 deletions
12
...hapter1.playgroundchapter/Pages/Asymmetric-Key Cryptography.playgroundpage/Manifest.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Name</key> | ||
<string>Asymmetric-Key Cryptography</string> | ||
<key>LiveViewEdgeToEdge</key> | ||
<true/> | ||
<key>LiveViewMode</key> | ||
<string>VisibleByDefault</string> | ||
</dict> | ||
</plist> |
27 changes: 27 additions & 0 deletions
27
...rs/Chapter1.playgroundchapter/Pages/Cryptography Foundation.playgroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//#-hidden-code | ||
// | ||
// See LICENSE folder for this template’s licensing information. | ||
// | ||
// Abstract: | ||
// The Swift file containing the source code edited by the user of this playground book. | ||
// | ||
//#-end-hidden-code | ||
/*: | ||
# Cryptography Foundation | ||
## What's Cryptography? | ||
In software development, we use cryptography to do a lot of things that are related to security, for example, encrypting and decrypting. | ||
## What Will We Learn | ||
In this playground book, we'll learn two of the most basic cryptography concepts so that you can secure the app: | ||
### Symmetric-Key Cryptography | ||
In symmetric-key cryptography, we use a key (just a password) which is shared between the sender and the receiver. Anyone holding the key can decrypt the content. | ||
### Asymmetric-Key Cryptography | ||
By contrast, in asymmetric-key cryptography, we use key-pairs. A key-pair is made up of a public key and a private key. After generating a key-pair, we keep the private one on our disk and share the public one to others. Anyone can encrypt a message using the public key, and only the holder of the corresponding private key can decrypt it. | ||
> A bit confused, or TL;DR? Don't be afraid! You'll understand how to use them in the following part with ease. | ||
[Let's Go!](@next) | ||
*/ | ||
//#-hidden-code | ||
import PlaygroundSupport | ||
PlaygroundPage.current.assessmentStatus = .pass(message: "[Let's go!](@next)") | ||
//#-end-hidden-code |
12 changes: 12 additions & 0 deletions
12
...rs/Chapter1.playgroundchapter/Pages/Cryptography Foundation.playgroundpage/LiveView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// See LICENSE folder for this template’s licensing information. | ||
// | ||
// Abstract: | ||
// Instantiates a live view and passes it to the PlaygroundSupport framework. | ||
// | ||
|
||
import UIKit | ||
import PlaygroundSupport | ||
|
||
// Instantiate a new instance of the live view from the book's auxiliary sources and pass it to PlaygroundSupport. | ||
PlaygroundPage.current.liveView = instantiateLiveView() |
12 changes: 12 additions & 0 deletions
12
...rs/Chapter1.playgroundchapter/Pages/Cryptography Foundation.playgroundpage/Manifest.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Name</key> | ||
<string>Cryptography Foundation</string> | ||
<key>LiveViewEdgeToEdge</key> | ||
<true/> | ||
<key>LiveViewMode</key> | ||
<string>VisibleByDefault</string> | ||
</dict> | ||
</plist> |
10 changes: 10 additions & 0 deletions
10
...ntents/Chapters/Chapter1.playgroundchapter/Pages/Introduction.cutscenepage/Manifest.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CutsceneReference</key> | ||
<string>WWDC19 Cutscene1.html</string> | ||
<key>Name</key> | ||
<string>Introduction</string> | ||
</dict> | ||
</plist> |
32 changes: 32 additions & 0 deletions
32
....playgroundchapter/Pages/Introduction.cutscenepage/PrivateResources/WWDC19 Cutscene1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge" /> | ||
<title>WWDC19 Cutscene1</title> | ||
<style> | ||
html { | ||
height:100%; | ||
} | ||
body { | ||
background-color:#FFFFFF; | ||
margin:0; | ||
height:100%; | ||
} | ||
</style> | ||
<!-- copy these lines to your document head: --> | ||
|
||
<meta name="viewport" content="user-scalable=no, width=device-height" /> | ||
|
||
<!-- end copy --> | ||
</head> | ||
<body> | ||
<!-- copy these lines to your document: --> | ||
|
||
<div id="wwdc19cutscene1_hype_container" style="margin:auto;position:relative;width:2732px;height:2048px;overflow:hidden;"> | ||
<script type="text/javascript" charset="utf-8" src="WWDC19%20Cutscene1.hyperesources/wwdc19cutscene1_hype_generated_script.js?12474"></script> | ||
</div> | ||
|
||
<!-- end copy --> | ||
</body> | ||
</html> |
Binary file added
BIN
+36.5 KB
...tion.cutscenepage/PrivateResources/WWDC19 Cutscene1.hyperesources/D367C0-restorable.plist
Binary file not shown.
Oops, something went wrong.