mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
16 lines
625 B
Swift
16 lines
625 B
Swift
import Foundation
|
|
import CryptoSwift
|
|
|
|
func decrypt(data: Data, key: String, salt: String) -> String? {
|
|
let keyBytes = key.data(using: .utf8)?.bytes ?? []
|
|
let saltBytes = salt.data(using: .utf8)?.bytes ?? []
|
|
|
|
guard let PBKDF2key = try? PKCS5.PBKDF2(password: keyBytes, salt: saltBytes, iterations: 4096, variant: .sha256).calculate(),
|
|
let cipher = try? Blowfish(key: PBKDF2key, padding: .pkcs7),
|
|
let decryptedBytes = try? cipher.decrypt(data.bytes) else {
|
|
return nil
|
|
}
|
|
|
|
let decryptedData = Data(decryptedBytes)
|
|
return String(data: decryptedData, encoding: .utf8)
|
|
}
|