作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 Lumberjack 作为日志记录平台(Objective C/Swift)有没有办法将日志加密写入文件?
最佳答案
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)"
}
}
}
关于ios - 伐木 worker iOS : How to write encrypted logs (Block Encryption),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37371566/
我是一名优秀的程序员,十分优秀!