Swift
Swift
Example: Crypt2.ClearEncryptCerts method
Demonstrates how to call the ClearEncryptCerts method.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let crypt = CkoCrypt2()!
// Tell the crypt object to use 3 certificates.
// Do this by calling AddEncryptCert for each certificate.
let cert1 = CkoCert()!
// ...
// Load the cert from a source such as a .pfx/.p12 file, smart card, USB token, Apple keychain, Windows certificate store, etc.
// ...
crypt.addEncryptCert(cert: cert1)
let cert2 = CkoCert()!
// ...
crypt.addEncryptCert(cert: cert2)
let cert3 = CkoCert()!
// ...
crypt.addEncryptCert(cert: cert3)
// Params for public-key encryption to create PKCS7 enveloped-data
crypt.cryptAlgorithm = "pki"
crypt.pkcs7CryptAlg = "aes"
crypt.keyLength = 256
crypt.oaepHash = "sha256"
crypt.oaepPadding = true
let bd = CkoBinData()!
// ...
success = crypt.encryptBd(bd: bd)
// Let's say we now want to encrypt something else with different certs..
// First clear the encryption certs.
crypt.clearEncryptCerts()
let cert4 = CkoCert()!
// ...
crypt.addEncryptCert(cert: cert4)
let cert5 = CkoCert()!
// ...
crypt.addEncryptCert(cert: cert5)
// ...
// ...
// Encrypt using cert4 and cert5.
success = crypt.encryptBd(bd: bd)
}