(Swift) RSASSA-PSS Algorithm with SHA256 Hashing
RSA encrypt a SHA256 hash with OAEP padding.
func chilkatTest() {
// 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.)
var success: Bool = privkey.loadPemFile("somePath/myPrivateKey.pem")
if success != true {
print("\(privkey.lastErrorText!)")
return
}
let rsa = CkoRsa()!
// Use RSA-PSS by setting OaepPadding = true
rsa.oaepPadding = true
// Use SHA256
rsa.oaepHash = "SHA-256"
rsa.importPrivateKeyObj(privkey)
// Generate a base64 signature.
rsa.encodingMode = "base64"
var sigStr: String? = rsa.signStringENC("String to be signed", hashAlg: "SHA-256")
if rsa.lastMethodSuccess != true {
print("\(rsa.lastErrorText!)")
return
}
print("Signature: \(sigStr!)")
}
|