Skip to content

Instantly share code, notes, and snippets.

View benbahrenburg's full-sized avatar

Ben Bahrenburg benbahrenburg

View GitHub Profile
@benbahrenburg
benbahrenburg / load-example.swift
Last active January 1, 2017 21:55
Load PDF Examples
let pdfData = try Data(contentsOf: URL(fileURLWithPath: "Path to pdf"))
@benbahrenburg
benbahrenburg / unlock.swift
Last active January 1, 2017 21:20
Unlock a PDF document
if let pdf = unlock(data: pdfData, password: "Hello World") {
print("You now have an unlocked CGPDFDocument")
}
func unlock(data: Data, password: String) -> CGPDFDocument? {
if let pdf = CGPDFDocument(CGDataProvider(data: data as CFData)!) {
guard pdf.isEncrypted == true else { return pdf }
guard pdf.unlockWithPassword("") == false else { return pdf }
@benbahrenburg
benbahrenburg / PDFHelpers.swift
Last active June 2, 2020 17:52
Removing PDF password using Swift
//
// PDF.swift
//
// Created by Ben Bahrenburg on 1/1/17.
// Copyright © 2017 bencoding.. All rights reserved.
//
import UIKit
open class PDFHelpers {
@benbahrenburg
benbahrenburg / deviceOwnerAuthentication.swift
Created January 1, 2017 03:52
Use LAContext to check if the device has a passcode
public func devicePasscodeEnabled() -> Bool {
return LAContext().canEvaluatePolicy(.deviceOwnerAuthentication, error: nil)
}
@benbahrenburg
benbahrenburg / Passcode+Keychain.swift
Last active January 1, 2017 04:09
Use the Keychain to determine if the device has a passcode set.
@available(iOS 8.0, *)
public func devicePasscodeEnabledUsingKeychain() -> Bool {
let query: [String:Any] = [
kSecClass as String : kSecClassGenericPassword,
kSecAttrAccount as String : UUID().uuidString,
kSecAttrAccessible as String: kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
kSecValueData as String: "HelloWorld".data(using: String.Encoding.utf8)!,
kSecReturnAttributes as String : kCFBooleanTrue
]
@benbahrenburg
benbahrenburg / PasscodeUtils.swift
Last active July 8, 2020 13:00
Use Swift to determine if device has passcode set
//
// PasscodeUtils.swift
//
// Created by Ben Bahrenburg on 12/31/16.
// Copyright © 2016 bencoding.com. All rights reserved.
//
import Foundation
import LocalAuthentication
@benbahrenburg
benbahrenburg / entitlement.xml
Created December 30, 2016 22:53
Example Entitlement for Keychain Sharing
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.bencoding.awesome-group</string>
</array>
let info = KeyChainAccessGroupHelper.getAccessGroupInfo()
//Use the default Keychain group
let keychain = Keychain(service: "com.example.github-token", accessGroup: info.rawValue)
//Use the prefix to connect to another keychain group
let keychain = Keychain(service: "com.example.github-token", accessGroup: String(format: "%@.com.bencoding.awesome-group", info.prefix))
@benbahrenburg
benbahrenburg / KeyChainAccessGroupHelper.swift
Last active July 5, 2021 21:18
KeyChainAccessGroupHelper - Making it easier to deal with Keychain Access Groups
//
// KeyStorage - Simplifying securely saving key information
//
// KeyChainAccessGroupHelper.swift
// Created by Ben Bahrenburg on 12/30/16.
// Copyright © 2017 bencoding.com. All rights reserved.
//
import Foundation
import Security
@benbahrenburg
benbahrenburg / Obfuscator.swift
Created September 19, 2016 00:38 — forked from MathieuWhite/Obfuscator.swift
Obfuscator for Swift
//
// Obfuscator.swift
// SwiftObfuscatorExample
//
// Created by Mathieu White on 2016-07-03.
// Copyright © 2016 Mathieu White. All rights reserved.
//
import Foundation