Please can anyone help me convert RSA public keys (they are either RSA OAEP SHA256 keys for encryption / decryption or RSA SSA PKCS1 v1.5 with SHA256 hashes for signing / verifying). iOS spits out keys in PKCS#1 format and WebCrypto on web browsers uses SPKI. I need interoperability between the two platforms, and am attempting to use Bouncy Castle in C# on the server (web api) to convert between the two formats.
Have been looking on the internet especially stack overflow and I can successfully convert from SPKI to PKCS1, thus: public static byte[] TranslateKeyInSpkiDERFormatToPKCS1(byte[] keyInSpkiFormat) { SubjectPublicKeyInfo spkiInfo = SubjectPublicKeyInfo.GetInstance((Asn1Sequence) Asn1Object.FromByteArray(keyInSpkiFormat)); byte[] keyInPKCS1Format = spkiInfo.GetPublicKey().GetDerEncoded(); return keyInPKCS1Format; } Have been struggling to write a method that does the reverse - that converts PKCS#1 to SPKI - I wonder if someone has done something similar. Thanks very much