Slide 22
Slide 22 text
String Extensionへの暗号化処理の定義例
func encrypt(key: SymmetricKey,
nonce: AES.GCM.Nonce) throws -> String {
guard let data = self.data(using: .utf8) else { throw NSError() }
// SealedBoxを生成
let seal = try AES.GCM.seal(data, using: key, nonce: nonce)
// 暗号化結果の取得
guard let encrypted = seal.combined?.base64EncodingString() else {
throw NSError() }
return encrypted
}