Skip to content
Snippets Groups Projects
Main.hs 710 B
Newer Older
  • Learn to ignore specific revisions
  • Jean-Paul Calderone's avatar
    Jean-Paul Calderone committed
    module Main where
    
    
    import qualified Crypto.PubKey.RSA as RSA
    
    Jean-Paul Calderone's avatar
    Jean-Paul Calderone committed
    import Data.ASN1.BinaryEncoding (DER (DER))
    import Data.ASN1.Encoding (ASN1Encoding (encodeASN1))
    import Data.ASN1.Types (ASN1Object (toASN1))
    import qualified Data.ByteString.Lazy as LB
    
    import Data.X509 (PrivKey (PrivKeyRSA))
    
    Jean-Paul Calderone's avatar
    Jean-Paul Calderone committed
    
    -- | The size of the keys to generate.
    bits :: Int
    bits = 2048
    
    -- | The number of keys to generate.
    count :: Int
    count = 5
    
    main :: IO ()
    main = do
    
        mapM_ genKey [0 .. count - 1]
    
    genKey :: Show a => a -> IO ()
    genKey n = do
        (_, priv) <- RSA.generate bits e
        let bytes = encodeASN1 DER (toASN1 (PrivKeyRSA priv) [])
        LB.writeFile ("test/data/rsa-privkey-" <> show n <> ".der") bytes
      where
        e = 0x10001