It kinda depends on what your Java back end is expecting. I suspect that you’re dealing with the difference between the RSAPublicKey structure, which is what Security framework generates, and the SubjectPublicKeyInfo structure, which is what a lot of third-party security toolkits expect. See On Cryptographic Key Formats for the details.
The easiest way to resolve this is on the back end, where you have access to a full-featured crypto toolkit. I can’t help you with the details though.
If you can’t change the server then you can do this an iOS but it’s a bit of a pain. There are two basic strategies:
The main drawback with A is that it only works for a specific key type and size. If you can live with that, it’s an easy option.
The problem with B, at least historically, is that iOS has no generic ASN.1 APIs and all the third-party ASN.1 coders out there are super complex. These days we have SwiftASN1, and that’s what I’d use if I decided to pursue B.
Finally, this problem goes away if you switch to EC because CryptoKit has great support for exporting EC public keys. And there are good reasons to switch to EC anyway. If you control the server, just change it to support EC. If not, discuss this with the folks who do control it, because RSA is long past its prime.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"