Last active
February 23, 2025 04:23
-
-
Save Daij-Djan/c169c6152831b34b8f853d0d04bd1429 to your computer and use it in GitHub Desktop.
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
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)" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is a draft only -- I use swiftyRSA