-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] [help-wanted] What format of public keys can be decoded? #100
Comments
Ok, after searching around, I kind of understand. I cannot use I actually discovered https://hackage.haskell.org/package/certificate-1.3.9 first and found out that is deprecated. Ideally, I would need the Any help in the right direction would be much appreciated! |
You can use the import qualified Data.PEM as PEM
import qualified Data.X509 as X509
import qualified Data.ByteString as B
import Data.ASN1.BinaryEncoding
import Data.ASN1.Types
import Data.ASN1.Encoding
main :: IO ()
main = do
rc <- B.readFile "test_rsa.pub.pkcs8"
let Right [pem] = PEM.pemParseBS rc
Right asn1 = decodeASN1' BER (PEM.pemContent pem)
Right (pub, []) = fromASN1 asn1
print (pub :: X509.PubKey) (with help from packages asn1-types and asn1-encoding) |
Thanks! So this works for PKCS8 formats. Is PKCS1 format also an instance of |
The The PKCS#1 format you referenced maps to the BitString inside this structure and is only possible for RSA because the algorithm has no parameter. I don't think there is API for this currently. Btw PKCS#8 is a format for private keys, not public keys. |
I'm a little confused with what format of public keys can be decoded by the
x509
package? (Also I'm not really super familiar with crypto formats etc.)I have a public key in two formats generated via openssh (converted using openssl):
and
Now I'm using
pem
to read the file first, and then trying todecodeSignedObject
it. Is that correct?I get the following output, with:
Left "signed object error: \"fromASN1: X509.PubKey: unknown format:[]\""
Left "signed object error: \"fromASN1: X509.PubKey: unknown format:[OID [1,2,840,113549,1,1,1],Null]\""
How can I decode a public key from any of these popular formats of public key?
The text was updated successfully, but these errors were encountered: