Swift
Swift
RSASSA-PSS Algorithm with SHA256 Hashing
See more RSA Examples
RSA encrypt a SHA256 hash with OAEP padding.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let privkey = CkoPrivateKey()!
// Load the private key object from a PEM file.
// (To load from a PEM string, call LoadPem instead.)
success = privkey.loadPemFile(path: "somePath/myPrivateKey.pem")
if success == false {
print("\(privkey.lastErrorText!)")
return
}
let rsa = CkoRsa()!
// Use RSA-PSS by setting PkcsPadding = false
rsa.pkcsPadding = false
// Use SHA256
rsa.oaepHash = "SHA-256"
rsa.usePrivateKey(privKey: privkey)
// Generate a base64 signature.
rsa.encodingMode = "base64"
var sigStr: String? = rsa.signStringENC(str: "String to be signed", hashAlg: "SHA-256")
if rsa.lastMethodSuccess == false {
print("\(rsa.lastErrorText!)")
return
}
print("Signature: \(sigStr!)")
}