{"action":"created","issue":{"url":"https://api.github.com/repos/haskell-crypto/cryptonite/issues/69","repository_url":"https://api.github.com/repos/haskell-crypto/cryptonite","labels_url":"https://api.github.com/repos/haskell-crypto/cryptonite/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/haskell-crypto/cryptonite/issues/69/comments","events_url":"https://api.github.com/repos/haskell-crypto/cryptonite/issues/69/events","html_url":"https://github.com/haskell-crypto/cryptonite/issues/69","id":136533369,"node_id":"MDU6SXNzdWUxMzY1MzMzNjk=","number":69,"title":"Reading/writing RSA keys from files","user":{"login":"timbod7","id":1996446,"node_id":"MDQ6VXNlcjE5OTY0NDY=","avatar_url":"https://avatars0.githubusercontent.com/u/1996446?v=4","gravatar_id":"","url":"https://api.github.com/users/timbod7","html_url":"https://github.com/timbod7","followers_url":"https://api.github.com/users/timbod7/followers","following_url":"https://api.github.com/users/timbod7/following{/other_user}","gists_url":"https://api.github.com/users/timbod7/gists{/gist_id}","starred_url":"https://api.github.com/users/timbod7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timbod7/subscriptions","organizations_url":"https://api.github.com/users/timbod7/orgs","repos_url":"https://api.github.com/users/timbod7/repos","events_url":"https://api.github.com/users/timbod7/events{/privacy}","received_events_url":"https://api.github.com/users/timbod7/received_events","type":"User","site_admin":false},"labels":[{"id":111605466,"node_id":"MDU6TGFiZWwxMTE2MDU0NjY=","url":"https://api.github.com/repos/haskell-crypto/cryptonite/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-02-25T22:37:29Z","updated_at":"2018-10-10T12:52:42Z","closed_at":null,"author_association":"NONE","body":"I'm using some of the functions in `Crypto.PubKey.RSA`, and wish to read and write PEM files compatible with openssl. I need functionality equivalent to these functions from [`OpenSSL.PEM`](http://haddock.stackage.org/lts-5.1/HsOpenSSL-0.11.1.1/OpenSSL-PEM.html):\n- writePKCS8PrivateKey\n- readPrivateKey\n- writePublicKey\n- readPublicKey\n\nAre there functions in some library compatible with  `Crypto.PubKey.RSA` to do this?\n"},"comment":{"url":"https://api.github.com/repos/haskell-crypto/cryptonite/issues/comments/428559462","html_url":"https://github.com/haskell-crypto/cryptonite/issues/69#issuecomment-428559462","issue_url":"https://api.github.com/repos/haskell-crypto/cryptonite/issues/69","id":428559462,"node_id":"MDEyOklzc3VlQ29tbWVudDQyODU1OTQ2Mg==","user":{"login":"asheshambasta","id":580365,"node_id":"MDQ6VXNlcjU4MDM2NQ==","avatar_url":"https://avatars3.githubusercontent.com/u/580365?v=4","gravatar_id":"","url":"https://api.github.com/users/asheshambasta","html_url":"https://github.com/asheshambasta","followers_url":"https://api.github.com/users/asheshambasta/followers","following_url":"https://api.github.com/users/asheshambasta/following{/other_user}","gists_url":"https://api.github.com/users/asheshambasta/gists{/gist_id}","starred_url":"https://api.github.com/users/asheshambasta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asheshambasta/subscriptions","organizations_url":"https://api.github.com/users/asheshambasta/orgs","repos_url":"https://api.github.com/users/asheshambasta/repos","events_url":"https://api.github.com/users/asheshambasta/events{/privacy}","received_events_url":"https://api.github.com/users/asheshambasta/received_events","type":"User","site_admin":false},"created_at":"2018-10-10T12:52:42Z","updated_at":"2018-10-10T12:52:42Z","author_association":"NONE","body":"If you're referring to reading RSA keys from PEM, I believe something like this achieves that:\r\n\r\n```haskell\r\nimport qualified Data.ByteString as B \r\nimport qualified Crypto.PubKey.OpenSsh.Decode as D\r\nimport qualified Crypto.PubKey.OpenSsh.Types as T\r\nimport qualified Crypto.Types.PubKey.RSA as CRSA\r\n\r\n-- |Read private RSA Key in PEM format\r\nreadPemRsaKey' :: MonadIO m\r\n               => FilePath\r\n               -- ^file path to read key from; must be PEM\r\n               -> m (Either PrivateKeyError CRSA.PrivateKey)\r\nreadPemRsaKey' path = do\r\n  exists <- liftIO $ doesFileExist path\r\n  if exists then do\r\n    eKey <- liftIO $ D.decodePrivate <$> B.readFile path\r\n    return $ case eKey of\r\n      Right (T.OpenSshPrivateKeyRsa k) -> Right k\r\n      Right other                    -> Left NotRSA\r\n      Left err                       -> Left $ ParseErr err\r\n  else return $ Left $ NoKey path\r\n\r\n```"}}
{"actor":{"display_login":"asheshambasta"}}