Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 40 lines (32 sloc) 1.27 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
import Control.Monad hiding (join)
import OpenSSL
import OpenSSL.EVP.PKey
import OpenSSL.PEM
import OpenSSL.RSA
import System.IO
import Text.Printf

main = withOpenSSL $
       do let keyBits = 512
              keyE = 65537

          printf "Generating RSA key-pair, nbits = %d, e = %d:\n" keyBits keyE
          
          rsa <- generateRSAKey keyBits keyE $ Just $ \ phase _ ->
                  do putChar $ case phase of
                                 0 -> '.'
                                 1 -> '+'
                                 2 -> '*'
                                 3 -> '\n'
                                 n -> head $ show n
                     hFlush stdout

          printf "Done.\n"
          
          let n = rsaN rsa
              e = rsaE rsa
              d = rsaD rsa
              p = rsaP rsa
              q = rsaQ rsa

          printf "n (public modulus) = %s\n" (show n)
          printf "e (public exponent) = %s\n" (show e)
          printf "d (private exponent) = %s\n" (show d)
          printf "p (secret prime factor) = %s\n" (show p)
          printf "q (secret prime factor) = %s\n" (show q)

          writePKCS8PrivateKey rsa Nothing >>= putStr
          writePublicKey rsa >>= putStr
Something went wrong with that request. Please try again.