First of all I know MD5 is "broken" and we shouldn't be using it but it's not my choice and there is legacy code I need to work with so for now at least I need to sign some data using MD5 and a RSA signing Key.
I think this is enough to explain the problem but I can share more code if needed.
I'm using this to sign:
let result = SecKeyRawSign(privateKey, SecPadding.PKCS1MD5, digestData.arrayOfBytes(), digestData.count, &signatureBytes, &signatureDataLength)
But that throws the error OSStatusCode -50 (parameter error from the Security framework)
If I change the padding to SecPadding.PKCS1SHA256 it works and after testing all the SecPadding options:
Fails with OSStatus -50:
OAEP
sigRaw
PKCS1MD2
PKCS1MD5
Works:
PKCS1
PKCS1SHA1
PKCS1SHA224
PKCS1SHA256
PKCS1SHA384
PKCS1SHA512
The digestData is created using CC_MD5 no matter which padding I've used so its stranger that it works with the SHA padding but not with MD5.
I'm getting a similar error when attempting to do this using the SwCrypt library, when using MD5 & PKCS1 padding I get the
OSStatus -4300 which is a parameter error from CommonCrypto.
let result = try CC.RSA.sign(paramString.data(using: .utf8)!, derKey: der, padding: .pkcs15, digest: .md5, saltLen: 0)
However I don't get an error if using the pss padding option.
So my question/s then, why am I getting this parameter error when using MD5 and PKCS1? Is it because use of MD5 is deprecated or could there be some problem with another parameter?
Any pointers would be greatly appreciated, I've been stuck trying to implement this all week.
1
0
1.2k