Skip to content

Instantly share code, notes, and snippets.

@Daij-Djan
Last active February 23, 2025 04:23
Show Gist options
  • Save Daij-Djan/c169c6152831b34b8f853d0d04bd1429 to your computer and use it in GitHub Desktop.
Save Daij-Djan/c169c6152831b34b8f853d0d04bd1429 to your computer and use it in GitHub Desktop.
import CocoaLumberjack
import Security
public class EncryptedLogger: DDAbstractLogger {
let key: SecKey!
let blockSize : Int
let padding : SecPadding
init(key: SecKey!, blockSize : Int = 128, padding: SecPadding = .PKCS1) {
self.key = key
self.blockSize = blockSize
self.padding = padding
}
convenience init(keyFilePath: String, blockSize: Int = 128, padding: SecPadding = .PKCS1) {
//TODO: load key from file
self.init(key: nil, blockSize: blockSize, padding: padding)
}
/**
* The log message method
*
* @param logMessage the message (model)
*/
public override func logMessage(logMessage: DDLogMessage!) {
let plainText = logFormatter != nil ? logFormatter.formatLogMessage(logMessage) : logMessage.message;
let plainTextData = [UInt8](plainText.utf8)
var encryptedData = [UInt8](count: Int(blockSize), repeatedValue: 0)
var encryptedDataLength = blockSize
let result = SecKeyEncrypt(key, padding, plainTextData, plainTextData.count, &encryptedData, &encryptedDataLength)
//TODO: write the encryptedData to a file or post it to some endpoint
//...
}
@objc
public override var loggerName: String! {
get {
return "\(self.dynamicType)"
}
}
}
@Daij-Djan
Copy link
Author

this is a draft only -- I use swiftyRSA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment