Skip to content

Instantly share code, notes, and snippets.

@mdelete
Created May 23, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdelete/3221fa912557f3144fdd to your computer and use it in GitHub Desktop.
Save mdelete/3221fa912557f3144fdd to your computer and use it in GitHub Desktop.
Silly but effective public key modulus extraction in Swift
func publicKeyHexModulus(key: SecKeyRef) -> String {
let s = String(format: "\(key)")
let r1 = s.rangeOfString("modulus: ")!
let r2 = Range<String.Index>(start: advance(r1.startIndex, count(r1)), end: advance(r1.endIndex, (SecKeyGetBlockSize(key) * 2)))
return s.substringWithRange(r2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment