I'm using SecKeyCreateSignature in Swift on iOS to sign my data with a 128 byte private key but the resulting signature has a size of 256 byte.
Here is the function I use for signing:
let algorithm: SecKeyAlgorithm = .rsaSignatureDigestPKCS1v15Raw
guard SecKeyIsAlgorithmSupported(privateKey, .sign, algorithm) else {
return nil
}
var error: Unmanaged<CFError>?
guard let signature = SecKeyCreateSignature(privateKey,
algorithm,
data as CFData,
&error) as Data? else {
return nil
}
Why is the signature size different to the key size? Shouldn't it be the same size?
Thanks in advance!
Edit: Here is a signature encoded in bas64 generated by a key pair with the keysize of 512 bit:
kMgncWoSSGY0je/b4WhW3WupFo4N83skfvT4kDm2uZigSlSzCfh0NT3tgRR2n5VAEhxxfJxQEhv/LA9VmwOirw6lzwYR7Ori4lr2+dj4Ox3L2aj8VytF13OvuY7dTonQknqRkiZLigyvHZLn9bMYMmAgkC35zvqp3NFJ4BkzLLE=
And the according public key in pkcs#1 format retrieved with SecKeyCopyExternalRepresentation:
3048024100e3a94a8119c5d3e3b36e83a4b30055dea0c23b9cfa2a44228f5ac3ee4d8e5b4d2a26060bd9a09bf6e5bb1b9cbb58e36171584dccbc008d55081ef461e1488be10203010001