mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
parent
fdfbb06e6c
commit
a14014f509
@ -45,7 +45,7 @@ struct CryptoSettingFields: Codable {
|
|||||||
let mode: String
|
let mode: String
|
||||||
let padding: String
|
let padding: String
|
||||||
let key: String?
|
let key: String?
|
||||||
let iv: String?
|
var iv: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AESCryptoModel {
|
struct AESCryptoModel {
|
||||||
|
|||||||
@ -234,10 +234,15 @@ class NotificationService: UNNotificationServiceExtension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func decrypt(ciphertext: String) throws -> [String: Any] {
|
func decrypt(ciphertext: String, iv: String? = nil) throws -> [String: Any] {
|
||||||
guard let fields = CryptoSettingManager.shared.fields else {
|
guard var fields = CryptoSettingManager.shared.fields else {
|
||||||
throw "No encryption key set"
|
throw "No encryption key set"
|
||||||
}
|
}
|
||||||
|
if let iv = iv {
|
||||||
|
// Support using specified IV decryption
|
||||||
|
fields.iv = iv
|
||||||
|
}
|
||||||
|
|
||||||
let aes = try AESCryptoModel(cryptoFields: fields)
|
let aes = try AESCryptoModel(cryptoFields: fields)
|
||||||
|
|
||||||
let json = try aes.decrypt(ciphertext: ciphertext)
|
let json = try aes.decrypt(ciphertext: ciphertext)
|
||||||
@ -258,8 +263,8 @@ class NotificationService: UNNotificationServiceExtension {
|
|||||||
// 如果是加密推送,则使用密文配置 bestAttemptContent
|
// 如果是加密推送,则使用密文配置 bestAttemptContent
|
||||||
if let ciphertext = userInfo["ciphertext"] as? String {
|
if let ciphertext = userInfo["ciphertext"] as? String {
|
||||||
do {
|
do {
|
||||||
var map = try decrypt(ciphertext: ciphertext)
|
var map = try decrypt(ciphertext: ciphertext, iv: userInfo["iv"] as? String)
|
||||||
for (key,val) in map {
|
for (key, val) in map {
|
||||||
// 将key重写为小写
|
// 将key重写为小写
|
||||||
map[key.lowercased()] = val
|
map[key.lowercased()] = val
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user