Skip to content

Instantly share code, notes, and snippets.

@christian-marie
Created January 9, 2015 03:21
Show Gist options
  • Save christian-marie/21421d86c8e5a1b06408 to your computer and use it in GitHub Desktop.
Save christian-marie/21421d86c8e5a1b06408 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe
import OpenSSL.EVP.Sign
import OpenSSL.EVP.Verify
import OpenSSL.EVP.Digest
import OpenSSL.PEM
import OpenSSL
import Control.Applicative
main :: IO ()
main =
-- Set up ctx, *important*
withOpenSSL $ do
-- Read the private key generated via openssl genrsa -out key.pem 2048
--
-- PwNone means that there shouldn't be a password
pri <- readFile "key.pem" >>= flip readPrivateKey PwNone
sha <- fromMaybe (error "no sha256") <$> getDigestByName "sha256"
let msg = "hello"
signature <- signBS sha pri msg
-- Client side verification now.
-- If you have access to the private key, you can simply use that.
pub <- readFile "key.pub" >>= readPublicKey
-- Result is VerifySuccess or VerifyFailure
verifyBS sha signature pub msg >>= print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment