(Swift 3,4,5...) RSA Sign using Base64 Private Key
Signs a string using a non-encrypted RSA private key in base64 encoding. Returns the RSA signature as a base64 string.
func chilkatTest() {
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let privKey = CkoPrivateKey()!
var success: Bool
let sbPem = CkoStringBuilder()!
sbPem.appendLine("-----BEGIN RSA PRIVATE KEY-----", crlf: true)
sbPem.appendLine("MIIC .... j5A==", crlf: true)
sbPem.appendLine("-----END RSA PRIVATE KEY-----", crlf: true)
success = privKey.loadPem(sbPem.getAsString())
if success != true {
print("\(privKey.lastErrorText!)")
return
}
let rsa = CkoRsa()!
success = rsa.importPrivateKeyObj(privKey)
if success != true {
print("\(rsa.lastErrorText!)")
return
}
rsa.encodingMode = "base64"
var strSigned: String? = rsa.openSslSignStringENC("12345678")
print("\(strSigned!)")
var strOriginal: String? = rsa.openSslVerifyStringENC(strSigned)
print("\(strOriginal!)")
}
|