Created
April 22, 2022 12:06
-
-
Save astrokin/5662bf0b823f61837236e3d6fb6f3684 to your computer and use it in GitHub Desktop.
Decrypt on iOS (CBC, Pkcs7, EVP_BytesToKey)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EVP_KDF_Util { | |
public class func generate_evp_kdf_aes256cbc_key_iv(pass: String, saltData: [UInt8]) throws -> (String, String) { | |
let passData = [UInt8](pass.data(using: .utf8)!) | |
let keySize: Int = 32 | |
let keyPointer = UnsafeMutablePointer<UInt8>.allocate(capacity: keySize) | |
keyPointer.initialize(repeating: 0, count: keySize) | |
let ivSize: Int = 16 | |
let ivPointer = UnsafeMutablePointer<UInt8>.allocate(capacity: ivSize) | |
ivPointer.initialize(repeating: 0, count: ivSize) | |
let err = gen_evp_kdf_aes256cbc(passData, saltData, keyPointer, ivPointer) | |
if err != ECE_OK { | |
throw PushCryptoError.decryptionError(errCode: err) | |
} | |
let key = Data(bytes: keyPointer, count: keySize).map({ String(format: "%02hhx", $0) }).joined() | |
let iv = Data(bytes: ivPointer, count: ivSize).map({ String(format: "%02hhx", $0) }).joined() | |
return (key, iv) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment