| 1 | import Foundation |
| 2 | import CryptoSwift |
| 3 | |
| 4 | func decrypt(data: Data, key: String, salt: String) -> String? { |
| 5 | let keyBytes = key.data(using: .utf8)?.bytes ?? [] |
| 6 | let saltBytes = salt.data(using: .utf8)?.bytes ?? [] |
| 7 | |
| 8 | guard let PBKDF2key = try? PKCS5.PBKDF2(password: keyBytes, salt: saltBytes, iterations: 4096, variant: .sha256).calculate(), |
| 9 | let cipher = try? Blowfish(key: PBKDF2key, padding: .pkcs7), |
| 10 | let decryptedBytes = try? cipher.decrypt(data.bytes) else { |
| 11 | return nil |
| 12 | } |
| 13 | |
| 14 | let decryptedData = Data(decryptedBytes) |
| 15 | return String(data: decryptedData, encoding: .utf8) |
| 16 | } |