Skip to content

Instantly share code, notes, and snippets.

@aguilarpgc
Created October 4, 2018 15:54
Show Gist options
  • Select an option

  • Save aguilarpgc/9e9c3eae7d26ebca7908471062a73b0b to your computer and use it in GitHub Desktop.

Select an option

Save aguilarpgc/9e9c3eae7d26ebca7908471062a73b0b to your computer and use it in GitHub Desktop.
extract key from PEM text
//
// 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