(Swift) 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!)")
}
|