Created
October 4, 2018 15:54
-
-
Save aguilarpgc/9e9c3eae7d26ebca7908471062a73b0b to your computer and use it in GitHub Desktop.
extract key from PEM text
This file contains hidden or 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
| // | |
| // StringPEM.swift | |
| // TestPEM | |
| // | |
| // Created by Paul Aguilar on 10/4/18. | |
| // Copyright © 2018 Paul Aguilar. All rights reserved. | |
| // | |
| import Foundation | |
| public extension String { | |
| // MARK: Methods | |
| private func plain() -> String { | |
| return String(self.filter { !" \n\t\r".contains($0) }) | |
| } | |
| public func plainPEM() -> String { | |
| return self.split(separator: "\n").reduce("") { (result, next) -> String in | |
| guard !next.contains("-----") else { | |
| return result | |
| } | |
| let plainNext = String(next).plain() | |
| return result + plainNext | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment