Base64 Decoding Failed (asn1ParsingFailed)
MarkParker5 opened this issue · 0 comments
MarkParker5 commented
I have the base64-encoded public key
let publicKey = "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxRks1TFBsclEwanpwSnhEN2VWQgpVYTBLVmVDT1o4akFaWVI0T0NWSzVlZlRGMzdHSXBlWmxrUHVVcWJsR2M4akJVMEQrMnVqU29xVUh4d1c2TmRDCklaUjBZblU4dGJNWVoyRTRlVTVzZkdySmdIbm1scEZnYlA4SDZyRWt3emZlQm03NGhkd1dXeFU4WHVtWDdUNVoKRlJHai9lRUp0a3pCMDhkS2hKckJuTTBTRzhscXU0S3k2cmd2cXh0VC9ENmNhN0g4ZVpDV0MzM29PditvSm9ITwpmd3dFRHVJVThncGFrWmNhZWpBTWVWVVdYUStES0s4THo0YmRjUGwzSUJrNFVHdTN5bVRFN2gxb3RQaDBPUUNICm5vUk1QNTdZNmMvVmVYQytmRnZXTy9mUEphUU9MYk9jV0poTFFTVGlFUTJHNzdZcnc3UDlDb1FFTWxnZDc5ZloKZlFJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg=="
When I am trying:
try PublicKey(base64Encoded: publicKey) // throws error
It throws error:
asn1ParsingFailed Couldn't parse the ASN1 key data. Please file a bug at https://goo.gl/y67MW6
But the next code is working:
guard
let publicKeyData = Data(base64Encoded: publicKey),
let publicKeyPem = String(data: publicKeyData, encoding: .utf8)
else {
print("Can't decode base64")
return
}
try PublicKey(pemEncoded: publicKeyPem) // is working