mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +00:00
17 lines
625 B
Swift
17 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)
|
||
|
}
|