Created
January 9, 2015 03:21
-
-
Save christian-marie/21421d86c8e5a1b06408 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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