From 63e970ce9cee4b942c931df7f611a2ed5d72247a Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Mon, 17 Jul 2017 15:37:46 -0400
Subject: [PATCH 01/13] added rsa dependency

---
 .DS_Store            | Bin 0 -> 6148 bytes
 JSONWebToken.podspec |   1 +
 2 files changed, 1 insertion(+)
 create mode 100644 .DS_Store

diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..4109f5729ae5463a19796b507aa5b3b48b1c88f0
GIT binary patch
literal 6148
zcmeHK!Ab-%41Li(EQqj2kNpB+|6o`~5U(qUH(^E;ahOG1@YrwgkMtk>4?n?|Cdv*D
z3tnWE1lpIjNv3%)Z393S>vj&z08H5wMU@fJ>CvS<H=Yos#CSr39xbl18VR(EQ@Zy<
zoZ$lJIL7AwADGGA{mp#Y^qpt(a=P8R>+8B*KQ_SI^Xp|vcT4Q9Z+~FDy4~E#`z~@B
zdkO}EfnXpQ_!|uH&Q_To7)Boq1Ovgq7Xx}eBsRs$F&mbngIy^Bi295!LS1VK^+}GE
zV>aXpMa-3GuHq$zm^<f_+f|O)(A*(je29Pfvv`s6b;eJ{98wuZ9}ENoLk9M3IMe(8
zgul#akw0{aQ7{k;{4)k*QZMTTlk&UuTY7reCbla!6}8K%P^b?c0UYQ#a#R*=J*iH+
X$}t;i6rC^b#CQl4LZS->eu04xq2Dwq

literal 0
HcmV?d00001

diff --git a/JSONWebToken.podspec b/JSONWebToken.podspec
index 2bf5306..708c2b3 100644
--- a/JSONWebToken.podspec
+++ b/JSONWebToken.podspec
@@ -13,5 +13,6 @@ Pod::Spec.new do |spec|
   spec.watchos.deployment_target = '2.0'
   spec.requires_arc = true
   spec.dependency 'CryptoSwift', '~> 0.6.1'
+  spec.dependency 'SwiftyRSA', '~> 1.2.0'
   spec.module_name = 'JWT'
 end

From 524bf4037eede243eddd82dd8e6c4abdf1741215 Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Mon, 17 Jul 2017 15:39:59 -0400
Subject: [PATCH 02/13] updated podspec

---
 JSONWebToken.podspec | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/JSONWebToken.podspec b/JSONWebToken.podspec
index 708c2b3..41e9fbe 100644
--- a/JSONWebToken.podspec
+++ b/JSONWebToken.podspec
@@ -5,7 +5,7 @@ Pod::Spec.new do |spec|
   spec.homepage = 'https://github.com/kylef/JSONWebToken.swift'
   spec.license = { :type => 'BSD', :file => 'LICENSE' }
   spec.author = { 'Kyle Fuller' => 'kyle@fuller.li' }
-  spec.source = { :git => 'https://github.com/kylef/JSONWebToken.swift.git', :tag => "#{spec.version}" }
+  spec.source = { :git => 'https://github.com/popwarfour/JSONWebToken.swift.git', :tag => "#{spec.version}" }
   spec.source_files = 'Sources/*.swift'
   spec.ios.deployment_target = '8.0'
   spec.osx.deployment_target = '10.9'

From 61a8be118ff122339a7e5a1db42c9831015d8964 Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Mon, 17 Jul 2017 16:24:04 -0400
Subject: [PATCH 03/13] updated podspec

---
 .DS_Store            | Bin 6148 -> 6148 bytes
 JSONWebToken.podspec |   6 +++---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/.DS_Store b/.DS_Store
index 4109f5729ae5463a19796b507aa5b3b48b1c88f0..68b081b64a834169d358e17db0862f6a18dafd2a 100644
GIT binary patch
delta 77
zcmZoMXffDe!N_!T$z&czxyccXJS=Ao85lquf!zEQmz2_yWCn(-lVF1U1sR6H$@#ej
W3?RU$u=ygR8Qa7LzRm0$fB6Ai6cv{M

delta 77
zcmZoMXffDe!N_#bV=@n;+~f#G9+pFq3=ANSKyH4DOG;@;G6TcaNiaeFf(*mp<ow(M
V1~B-r`68nk+r$RG&Fmb1`2kY!7Ayb&

diff --git a/JSONWebToken.podspec b/JSONWebToken.podspec
index 41e9fbe..11dd8df 100644
--- a/JSONWebToken.podspec
+++ b/JSONWebToken.podspec
@@ -7,10 +7,10 @@ Pod::Spec.new do |spec|
   spec.author = { 'Kyle Fuller' => 'kyle@fuller.li' }
   spec.source = { :git => 'https://github.com/popwarfour/JSONWebToken.swift.git', :tag => "#{spec.version}" }
   spec.source_files = 'Sources/*.swift'
-  spec.ios.deployment_target = '8.0'
+  spec.ios.deployment_target = '8.3'
   spec.osx.deployment_target = '10.9'
-  spec.tvos.deployment_target = '9.0'
-  spec.watchos.deployment_target = '2.0'
+  spec.tvos.deployment_target = '9.2'
+  spec.watchos.deployment_target = '2.2'
   spec.requires_arc = true
   spec.dependency 'CryptoSwift', '~> 0.6.1'
   spec.dependency 'SwiftyRSA', '~> 1.2.0'

From 41b20dbd158fdef6008a0531e41d3c8dde9e7f44 Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Mon, 17 Jul 2017 16:38:58 -0400
Subject: [PATCH 04/13] updated podspec

---
 .DS_Store            | Bin 6148 -> 6148 bytes
 JSONWebToken.podspec |   2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/.DS_Store b/.DS_Store
index 68b081b64a834169d358e17db0862f6a18dafd2a..3deb28f63ec73519652faa2d2fa1222c7a32a6bc 100644
GIT binary patch
delta 33
pcmZoMXffDe!N~L^crp*8+~f$xEJlOP7a7giCN}VGX6N|J4*;{L3Vr|p

delta 33
pcmZoMXffDe!N_!T$z&czxyccXS&RysFEX03O>E%X%+B$b9{{;b3bX(K

diff --git a/JSONWebToken.podspec b/JSONWebToken.podspec
index 11dd8df..a614f74 100644
--- a/JSONWebToken.podspec
+++ b/JSONWebToken.podspec
@@ -1,6 +1,6 @@
 Pod::Spec.new do |spec|
   spec.name = 'JSONWebToken'
-  spec.version = '2.1.1'
+  spec.version = '2.1.2'
   spec.summary = 'Swift library for JSON Web Tokens (JWT).'
   spec.homepage = 'https://github.com/kylef/JSONWebToken.swift'
   spec.license = { :type => 'BSD', :file => 'LICENSE' }

From e3928a9be633dcf651951c4a1bdd8164b3a6a7fc Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Mon, 17 Jul 2017 17:32:05 -0400
Subject: [PATCH 05/13] added rsa 256

---
 .DS_Store            | Bin 6148 -> 6148 bytes
 Sources/Decode.swift |  40 ++++++++++++++++++------------------
 Sources/Encode.swift |  22 ++++++++++----------
 Sources/JWT.swift    |  48 +++++++++++++++++++++++++++++++------------
 4 files changed, 66 insertions(+), 44 deletions(-)

diff --git a/.DS_Store b/.DS_Store
index 3deb28f63ec73519652faa2d2fa1222c7a32a6bc..f1b79697ac3dc453b11a9c5395940953d4868f81 100644
GIT binary patch
delta 19
acmZoMXffDe!N~N?a54|0+~x?zHDUlh>IL@z

delta 19
acmZoMXffDe!N~L^crp*8+~x?zHDUljC<Ye*

diff --git a/Sources/Decode.swift b/Sources/Decode.swift
index ce802d7..8a8b894 100644
--- a/Sources/Decode.swift
+++ b/Sources/Decode.swift
@@ -5,25 +5,25 @@ import Foundation
 public enum InvalidToken: CustomStringConvertible, Error {
   /// Decoding the JWT itself failed
   case decodeError(String)
-
+  
   /// The JWT uses an unsupported algorithm
   case invalidAlgorithm
-
+  
   /// The issued claim has expired
   case expiredSignature
-
+  
   /// The issued claim is for the future
   case immatureSignature
-
+  
   /// The claim is for the future
   case invalidIssuedAt
-
+  
   /// The audience of the claim doesn't match
   case invalidAudience
-
+  
   /// The issuer claim failed to verify
   case invalidIssuer
-
+  
   /// Returns a readable description of the error
   public var description: String {
     switch self {
@@ -49,12 +49,12 @@ public enum InvalidToken: CustomStringConvertible, Error {
 /// Decode a JWT
 public func decode(_ jwt: String, algorithms: [Algorithm], verify: Bool = true, audience: String? = nil, issuer: String? = nil) throws -> ClaimSet {
   let (header, claims, signature, signatureInput) = try load(jwt)
-
+  
   if verify {
     try claims.validate(audience: audience, issuer: issuer)
     try verifySignature(algorithms, header: header, signingInput: signatureInput, signature: signature)
   }
-
+  
   return claims
 }
 
@@ -82,35 +82,35 @@ func load(_ jwt: String) throws -> (header: JOSEHeader, payload: ClaimSet, signa
   if segments.count != 3 {
     throw InvalidToken.decodeError("Not enough segments")
   }
-
+  
   let headerSegment = segments[0]
   let payloadSegment = segments[1]
   let signatureSegment = segments[2]
   let signatureInput = "\(headerSegment).\(payloadSegment)"
-
+  
   guard let headerData = base64decode(headerSegment) else {
     throw InvalidToken.decodeError("Header is not correctly encoded as base64")
   }
-
+  
   let header = (try? JSONSerialization.jsonObject(with: headerData, options: JSONSerialization.ReadingOptions(rawValue: 0))) as? Payload
   if header == nil {
     throw InvalidToken.decodeError("Invalid header")
   }
-
+  
   let payloadData = base64decode(payloadSegment)
   if payloadData == nil {
     throw InvalidToken.decodeError("Payload is not correctly encoded as base64")
   }
-
+  
   let payload = (try? JSONSerialization.jsonObject(with: payloadData!, options: JSONSerialization.ReadingOptions(rawValue: 0))) as? Payload
   if payload == nil {
     throw InvalidToken.decodeError("Invalid payload")
   }
-
+  
   guard let signature = base64decode(signatureSegment) else {
     throw InvalidToken.decodeError("Signature is not correctly encoded as base64")
   }
-
+  
   return (header: JOSEHeader(parameters: header!), payload: ClaimSet(claims: payload!), signature: signature, signatureInput: signatureInput)
 }
 
@@ -120,11 +120,11 @@ func verifySignature(_ algorithms: [Algorithm], header: JOSEHeader, signingInput
   guard let alg = header.algorithm else {
     throw InvalidToken.decodeError("Missing Algorithm")
   }
-
-  let verifiedAlgorithms = algorithms
+  
+  let verifiedAlgorithms = try algorithms
     .filter { algorithm in algorithm.description == alg }
-    .filter { algorithm in algorithm.verify(signingInput, signature: signature) }
-
+    .filter { algorithm in try algorithm.verify(signingInput, signature: signature) }
+  
   if verifiedAlgorithms.isEmpty {
     throw InvalidToken.invalidAlgorithm
   }
diff --git a/Sources/Encode.swift b/Sources/Encode.swift
index fa716d1..24b509b 100644
--- a/Sources/Encode.swift
+++ b/Sources/Encode.swift
@@ -5,25 +5,25 @@ import Foundation
  - parameter algorithm: The algorithm to sign the payload with
  - returns: The JSON web token as a String
  */
-public func encode(claims: ClaimSet, algorithm: Algorithm, headers: [String: String]? = nil) -> String {
+public func encode(claims: ClaimSet, algorithm: Algorithm, headers: [String: String]? = nil) throws -> String {
   func encodeJSON(_ payload: [String: Any]) -> String? {
     if let data = try? JSONSerialization.data(withJSONObject: payload) {
       return base64encode(data)
     }
-
+    
     return nil
   }
-
+  
   var headers = headers ?? [:]
   if !headers.keys.contains("typ") {
     headers["typ"] = "JWT"
   }
   headers["alg"] = algorithm.description
-
+  
   let header = encodeJSON(headers)!
   let payload = encodeJSON(claims.claims)!
   let signingInput = "\(header).\(payload)"
-  let signature = algorithm.sign(signingInput)
+  let signature = try algorithm.sign(signingInput)
   return "\(signingInput).\(signature)"
 }
 
@@ -32,16 +32,16 @@ public func encode(claims: ClaimSet, algorithm: Algorithm, headers: [String: Str
  - parameter algorithm: The algorithm to sign the payload with
  - returns: The JSON web token as a String
  */
-public func encode(claims: [String: Any], algorithm: Algorithm, headers: [String: String]? = nil) -> String {
-  return encode(claims: ClaimSet(claims: claims), algorithm: algorithm, headers: headers)
+public func encode(claims: [String: Any], algorithm: Algorithm, headers: [String: String]? = nil) throws -> String {
+  return try encode(claims: ClaimSet(claims: claims), algorithm: algorithm, headers: headers)
 }
 
 
 /// Encode a set of claims using the builder pattern
-public func encode(_ algorithm: Algorithm, closure: ((ClaimSetBuilder) -> Void)) -> String {
+public func encode(_ algorithm: Algorithm, closure: ((ClaimSetBuilder) -> Void)) throws -> String {
   let builder = ClaimSetBuilder()
   closure(builder)
-  return encode(claims: builder.claims, algorithm: algorithm)
+  return try encode(claims: builder.claims, algorithm: algorithm)
 }
 
 
@@ -51,6 +51,6 @@ public func encode(_ algorithm: Algorithm, closure: ((ClaimSetBuilder) -> Void))
  - returns: The JSON web token as a String
  */
 @available(*, deprecated, message: "use encode(claims: algorithm:) instead")
-public func encode(_ payload: Payload, algorithm: Algorithm) -> String {
-  return encode(claims: ClaimSet(claims: payload), algorithm: algorithm)
+public func encode(_ payload: Payload, algorithm: Algorithm) throws -> String {
+  return try encode(claims: ClaimSet(claims: payload), algorithm: algorithm)
 }
diff --git a/Sources/JWT.swift b/Sources/JWT.swift
index 3b3e4a3..780f895 100644
--- a/Sources/JWT.swift
+++ b/Sources/JWT.swift
@@ -1,5 +1,6 @@
 import Foundation
 import CryptoSwift
+import SwiftyRSA
 
 public typealias Payload = [String: Any]
 
@@ -7,16 +8,19 @@ public typealias Payload = [String: Any]
 public enum Algorithm: CustomStringConvertible {
   /// No Algorithm, i-e, insecure
   case none
-
+  
   /// HMAC using SHA-256 hash algorithm
   case hs256(Data)
-
+  
   /// HMAC using SHA-384 hash algorithm
   case hs384(Data)
-
+  
   /// HMAC using SHA-512 hash algorithm
   case hs512(Data)
-
+  
+  /// RSA using SHA-256 hash algorithm
+  case rsa256(PrivateKey)
+  
   public var description: String {
     switch self {
     case .none:
@@ -27,11 +31,14 @@ public enum Algorithm: CustomStringConvertible {
       return "HS384"
     case .hs512:
       return "HS512"
+    case .rsa256:
+      return "RSA256"
     }
   }
-
+  
   /// Sign a message using the algorithm
-  func sign(_ message: String) -> String {
+  func sign(_ message: String) throws -> String {
+    
     func signHS(_ key: Data, variant: CryptoSwift.HMAC.Variant) -> String {
       let messageData = message.data(using: String.Encoding.utf8, allowLossyConversion: false)!
       let mac = HMAC(key: key.bytes, variant: variant)
@@ -43,24 +50,39 @@ public enum Algorithm: CustomStringConvertible {
       }
       return base64encode(Data(bytes: result))
     }
-
+    
+    func signRSA(_ privateKey: PrivateKey, digestType: Signature.DigestType) throws -> String {
+      
+      let clear = try ClearMessage(string: message, using: .utf8)
+      
+      let signature = try clear.signed(with: privateKey, digestType: digestType)
+      let base64Signature = signature.base64String
+      
+      return base64Signature
+      
+    }
+    
     switch self {
     case .none:
       return ""
-
+      
     case .hs256(let key):
       return signHS(key, variant: .sha256)
-
+      
     case .hs384(let key):
       return signHS(key, variant: .sha384)
-
+      
     case .hs512(let key):
       return signHS(key, variant: .sha512)
+      
+    case .rsa256(let privateKey):
+      return try signRSA(privateKey, digestType: .sha256)
+      
     }
   }
-
+  
   /// Verify a signature for a message using the algorithm
-  func verify(_ message: String, signature: Data) -> Bool {
-    return sign(message) == base64encode(signature)
+  func verify(_ message: String, signature: Data) throws -> Bool {
+    return try sign(message) == base64encode(signature)
   }
 }

From 41c47478301eb0aac536befe536b3d91bf2dd536 Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Tue, 18 Jul 2017 13:26:02 -0400
Subject: [PATCH 06/13] fixed algoirthm

---
 .DS_Store         | Bin 6148 -> 6148 bytes
 Sources/JWT.swift |   5 +++++
 2 files changed, 5 insertions(+)

diff --git a/.DS_Store b/.DS_Store
index f1b79697ac3dc453b11a9c5395940953d4868f81..2af93209cdf508902254897126bad8ab4c7b7427 100644
GIT binary patch
delta 19
acmZoMXffDe!N~MNaWW61+~x?zHDUlhU<K&_

delta 19
acmZoMXffDe!N~N?a54|0+~x?zHDUlh>IL@z

diff --git a/Sources/JWT.swift b/Sources/JWT.swift
index 780f895..55a955f 100644
--- a/Sources/JWT.swift
+++ b/Sources/JWT.swift
@@ -21,6 +21,9 @@ public enum Algorithm: CustomStringConvertible {
   /// RSA using SHA-256 hash algorithm
   case rsa256(PrivateKey)
   
+  // RSA using SHA-512 hash algorithm
+  case rsa512(PrivateKey)
+  
   public var description: String {
     switch self {
     case .none:
@@ -33,6 +36,8 @@ public enum Algorithm: CustomStringConvertible {
       return "HS512"
     case .rsa256:
       return "RSA256"
+    case .rsa512:
+      return "RS512"
     }
   }
   

From e7229468d45c10969a9ffc83a41d7e3b97db131f Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Tue, 18 Jul 2017 13:27:31 -0400
Subject: [PATCH 07/13] fixed algoirthm

---
 .DS_Store         | Bin 6148 -> 6148 bytes
 Sources/JWT.swift |  10 +++++-----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/.DS_Store b/.DS_Store
index 2af93209cdf508902254897126bad8ab4c7b7427..5a39bb1690bf45ea4d209ebae5f115c9582406c9 100644
GIT binary patch
delta 18
ZcmZoMXffDe$;hZYnTJtsa|GiWF#s|u1p@#8

delta 18
ZcmZoMXffDe$;hZUnTJtsa|GiWF#s|a1pxp6

diff --git a/Sources/JWT.swift b/Sources/JWT.swift
index 55a955f..8e7edc0 100644
--- a/Sources/JWT.swift
+++ b/Sources/JWT.swift
@@ -19,10 +19,10 @@ public enum Algorithm: CustomStringConvertible {
   case hs512(Data)
   
   /// RSA using SHA-256 hash algorithm
-  case rsa256(PrivateKey)
+  case rs256(PrivateKey)
   
   // RSA using SHA-512 hash algorithm
-  case rsa512(PrivateKey)
+  case rs512(PrivateKey)
   
   public var description: String {
     switch self {
@@ -34,9 +34,9 @@ public enum Algorithm: CustomStringConvertible {
       return "HS384"
     case .hs512:
       return "HS512"
-    case .rsa256:
-      return "RSA256"
-    case .rsa512:
+    case .rs256:
+      return "RS256"
+    case .rs512:
       return "RS512"
     }
   }

From a92e738764bce98224a6bf77254c521f32151552 Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Thu, 20 Jul 2017 12:45:51 -0400
Subject: [PATCH 08/13] Refactored

---
 Sources/JWT.swift | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/Sources/JWT.swift b/Sources/JWT.swift
index 8e7edc0..c4b7626 100644
--- a/Sources/JWT.swift
+++ b/Sources/JWT.swift
@@ -19,10 +19,10 @@ public enum Algorithm: CustomStringConvertible {
   case hs512(Data)
   
   /// RSA using SHA-256 hash algorithm
-  case rs256(PrivateKey)
+  case rs256(Data)
   
   // RSA using SHA-512 hash algorithm
-  case rs512(PrivateKey)
+  case rs512(Data)
   
   public var description: String {
     switch self {
@@ -56,7 +56,10 @@ public enum Algorithm: CustomStringConvertible {
       return base64encode(Data(bytes: result))
     }
     
-    func signRSA(_ privateKey: PrivateKey, digestType: Signature.DigestType) throws -> String {
+    func signRS(_ key: Data, digestType: Signature.DigestType) throws -> String {
+      
+      let keyString = String.init(data: key, encoding: .utf8)
+      let privateKey = try PrivateKey(pemEncoded: keyString)
       
       let clear = try ClearMessage(string: message, using: .utf8)
       
@@ -80,8 +83,11 @@ public enum Algorithm: CustomStringConvertible {
     case .hs512(let key):
       return signHS(key, variant: .sha512)
       
-    case .rsa256(let privateKey):
-      return try signRSA(privateKey, digestType: .sha256)
+    case .rs256(let key):
+      return try signRS(privateKey, digestType: .sha256)
+     
+    case .rs512(let key):
+      return try signRS(privateKey, digestType: .sha512)
       
     }
   }

From 4f2fbed2290015e2ea6b8c7152b6ccdbad13eb9b Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Thu, 20 Jul 2017 12:47:28 -0400
Subject: [PATCH 09/13] added RSA documentation

---
 README.md | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/README.md b/README.md
index 830f70d..b891baa 100644
--- a/README.md
+++ b/README.md
@@ -86,6 +86,9 @@ This library supports the following algorithms:
 - `hs256` - HMAC using SHA-256 hash algorithm (default)
 - `hs384` - HMAC using SHA-384 hash algorithm
 - `hs512` - HMAC using SHA-512 hash algorithm
+- `rs256` - RSA using SHA-256 hash algorithm
+- `rs512` - RSA using SHA-512 hash algorithm
+
 
 ## License
 

From b9de260ae5d9732403477319de72ace45aed7f13 Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Thu, 20 Jul 2017 12:56:52 -0400
Subject: [PATCH 10/13] minor change

---
 Sources/JWT.swift | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Sources/JWT.swift b/Sources/JWT.swift
index c4b7626..f454c37 100644
--- a/Sources/JWT.swift
+++ b/Sources/JWT.swift
@@ -46,6 +46,7 @@ public enum Algorithm: CustomStringConvertible {
     
     func signHS(_ key: Data, variant: CryptoSwift.HMAC.Variant) -> String {
       let messageData = message.data(using: String.Encoding.utf8, allowLossyConversion: false)!
+      
       let mac = HMAC(key: key.bytes, variant: variant)
       let result: [UInt8]
       do {
@@ -58,7 +59,7 @@ public enum Algorithm: CustomStringConvertible {
     
     func signRS(_ key: Data, digestType: Signature.DigestType) throws -> String {
       
-      let keyString = String.init(data: key, encoding: .utf8)
+      let keyString = message.data(using: String.Encoding.utf8, allowLossyConversion: false)!
       let privateKey = try PrivateKey(pemEncoded: keyString)
       
       let clear = try ClearMessage(string: message, using: .utf8)
@@ -85,7 +86,7 @@ public enum Algorithm: CustomStringConvertible {
       
     case .rs256(let key):
       return try signRS(privateKey, digestType: .sha256)
-     
+      
     case .rs512(let key):
       return try signRS(privateKey, digestType: .sha512)
       

From 51d4ee077655545de9a5a07a2be3d30aed0264d0 Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Sun, 30 Jul 2017 09:54:18 -0400
Subject: [PATCH 11/13] updated

---
 .DS_Store         | Bin 6148 -> 6148 bytes
 Package.pins      |  12 ++++++++++++
 Sources/JWT.swift |   7 +++----
 3 files changed, 15 insertions(+), 4 deletions(-)
 create mode 100644 Package.pins

diff --git a/.DS_Store b/.DS_Store
index 5a39bb1690bf45ea4d209ebae5f115c9582406c9..670eda9de70804ba6870b0672d2d8655a5c8c8e5 100644
GIT binary patch
delta 424
zcmZoMXfc=|#>B!ku~2NHo}wrl0|Nsi1A_nqLq0<qLncEJLn?#k=8KHWnd?DPd<>2Z
zISh#mxyaH$ULr#}LuyiaaY0f}eiBgKx1@rc%;FLQgBy%Y%q*;I>>Qk2+?-sT{G74D
z8TsYGC5a`a#ZHMu(I8$xVo63)Vo|(+OmJpODv%YPnNpGwlA7n5lUkOV=U?QLSdv;)
z4^|tJpPvI%0bwU5g=MCe#|wx!=jW9qX6B_9fenWk5)+=8my%!ZlwX>cQVdoPHJy_~
z*&!Y1Mj+ti;EWfLtgbe)FxOEqF*C2#QK&XFFtyN8FgCTQt>xs9R5uQa%WCYKHG59r
z(q+q69D(R#1O^cp2tsKXbri_J8%AZpMR_^-c_8~4H}f#AW!lWn!OsB<e_$AYXP(S2
VVkrPL8*Ds~U;>%DIYML&GXOpjYcK!+

delta 94
zcmZoMXfc=|#>B`mu~2NHo}wrV0|Nsi1A_nqLj^-JLq0<aLn=eT#KPr_ESsZP*D`HZ
o;9zH&*x<gIor9kPsB5zz$9Lw*{34b>4PcE-P?}|Pgvc6Z0G#F#>i_@%

diff --git a/Package.pins b/Package.pins
new file mode 100644
index 0000000..4afba9f
--- /dev/null
+++ b/Package.pins
@@ -0,0 +1,12 @@
+{
+  "autoPin": true,
+  "pins": [
+    {
+      "package": "CryptoSwift",
+      "reason": null,
+      "repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift",
+      "version": "0.6.9"
+    }
+  ],
+  "version": 1
+}
\ No newline at end of file
diff --git a/Sources/JWT.swift b/Sources/JWT.swift
index f454c37..15397e2 100644
--- a/Sources/JWT.swift
+++ b/Sources/JWT.swift
@@ -59,8 +59,7 @@ public enum Algorithm: CustomStringConvertible {
     
     func signRS(_ key: Data, digestType: Signature.DigestType) throws -> String {
       
-      let keyString = message.data(using: String.Encoding.utf8, allowLossyConversion: false)!
-      let privateKey = try PrivateKey(pemEncoded: keyString)
+      let privateKey = try PrivateKey(data: data)
       
       let clear = try ClearMessage(string: message, using: .utf8)
       
@@ -85,10 +84,10 @@ public enum Algorithm: CustomStringConvertible {
       return signHS(key, variant: .sha512)
       
     case .rs256(let key):
-      return try signRS(privateKey, digestType: .sha256)
+      return try signRS(key, digestType: .sha256)
       
     case .rs512(let key):
-      return try signRS(privateKey, digestType: .sha512)
+      return try signRS(key, digestType: .sha512)
       
     }
   }

From 9131013ef7c88cce69fe688965844d664cd7223d Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Sun, 30 Jul 2017 10:02:21 -0400
Subject: [PATCH 12/13] fixed typo

---
 Sources/JWT.swift | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Sources/JWT.swift b/Sources/JWT.swift
index 15397e2..615777d 100644
--- a/Sources/JWT.swift
+++ b/Sources/JWT.swift
@@ -59,7 +59,7 @@ public enum Algorithm: CustomStringConvertible {
     
     func signRS(_ key: Data, digestType: Signature.DigestType) throws -> String {
       
-      let privateKey = try PrivateKey(data: data)
+      let privateKey = try PrivateKey(data: key)
       
       let clear = try ClearMessage(string: message, using: .utf8)
       

From 73b5efef9de561b5ffb13f384f721d0a1deb75fd Mon Sep 17 00:00:00 2001
From: Anders Melen <popwarfour2@gmail.com>
Date: Sun, 30 Jul 2017 10:28:19 -0400
Subject: [PATCH 13/13] fix podspec

---
 JSONWebToken.podspec | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/JSONWebToken.podspec b/JSONWebToken.podspec
index a614f74..f628f4e 100644
--- a/JSONWebToken.podspec
+++ b/JSONWebToken.podspec
@@ -5,7 +5,7 @@ Pod::Spec.new do |spec|
   spec.homepage = 'https://github.com/kylef/JSONWebToken.swift'
   spec.license = { :type => 'BSD', :file => 'LICENSE' }
   spec.author = { 'Kyle Fuller' => 'kyle@fuller.li' }
-  spec.source = { :git => 'https://github.com/popwarfour/JSONWebToken.swift.git', :tag => "#{spec.version}" }
+  spec.source = { :git => 'https://github.com/kylef/JSONWebToken.swift.git', :tag => "#{spec.version}" }
   spec.source_files = 'Sources/*.swift'
   spec.ios.deployment_target = '8.3'
   spec.osx.deployment_target = '10.9'