-
Notifications
You must be signed in to change notification settings - Fork 139
Reading/writing RSA keys from files #69
Comments
There's some functions that do that in the certificate packages ( Edit: I'm thinking a new |
Thanks for the hint with Right now, I need to use I really think there should be a way to convert from the more common encodings (straight ASN1, PEM, etc.) directly to a |
@vincenthz Along with this, is it possible to add instances of ASN1Object for RSA private keys to support serialization/deserialization? |
Related issue in |
So I have read through the comments but I still don't understand which package to use to convert the @Xandaros's method doesn't work for me. They wanted Excuse my ignorance, I'm not familiar with crypto etc. My use-case is, I want to generate public, private key pair for SSH. Any nudge in the right direction would be appreciated. |
Is there a solution for ECDSA for this? |
@vincenthz I'd be willing to take on some of the work to do a cryptonite-storage library. Unless it's already started. to your knowledge is this already started or should I start a new project for it? |
FYI I have a package in progress for this, already able to parse (un)encrypted private keys. |
Has anyone had any success in writing a |
In case this may help anyone, here's my quick and (very) dirty solution for writing a |
We did something with this that can be found here:
ProofOfKeags/wai-jwt-auth-middleware#1
It's highly specific to the use case we needed it for. and I'm not sure it
writes. But in case it's useful I thought I'd share.
…On Tue, Aug 14, 2018 at 6:35 AM, Ashesh Ambasta ***@***.***> wrote:
In case this may help anyone, here's my quick and (very) dirty solution
for writing a PrivateKey as to PEM: https://gist.github.com/asheshambasta/
001986992ad41ee82e4b042054df4efb
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD2Mc1oMY7uRieTk534pzdkDxhgLPEpvks5uQsQkgaJpZM4HjQ_B>
.
|
@asheshambasta do you have solution for reading? |
@sigrlami If you're referring to reading RSA keys from PEM, I believe something like this achieves that: import qualified Data.ByteString as B
import qualified Crypto.PubKey.OpenSsh.Decode as D
import qualified Crypto.PubKey.OpenSsh.Types as T
import qualified Crypto.Types.PubKey.RSA as CRSA
-- | Read private RSA Key in PEM format
readPemRsaKey' :: MonadIO m
=> FilePath -- ^ file path to read key from; must be PEM
-> m (Either PrivateKeyError CRSA.PrivateKey)
readPemRsaKey' path = do
exists <- liftIO $ doesFileExist path
if exists then do
eKey <- liftIO $ D.decodePrivate <$> B.readFile path
return $ case eKey of
Right (T.OpenSshPrivateKeyRsa k) -> Right k
Right other -> Left NotRSA
Left err -> Left . ParseErr $ err
else return . Left . NoKey $ path
edit: cleaned up the snippet. |
@vincenthz What's the status of cryptonite-storage? I was thinking of creating something similar. |
It's there: https://github.com/ocheron/cryptostore. |
@asheshambasta thanks for your snippet. Using it, I was able to successfully parse a I don't see any way to convert between the two libraries' I feel like I'm doing something silly wrt dependency management. For what it's worth, I'm using stack with the Here is my type-error.
Any ideas? @Xandaros I read through your comment and suspect I could do something similar to library-hop my way from a |
@mDantas I've encountered this before. The problem is what you've correctly identified: the |
@mDantas The x509 package defines a |
This just drove me crazy. So Then @CaptJakk 's recommendation works great: ProofOfKeags/wai-jwt-auth-middleware#1 |
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 fromOpenSSL.PEM
:Are there functions in some library compatible with
Crypto.PubKey.RSA
to do this?The text was updated successfully, but these errors were encountered: