diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2011-08-12 21:05:31 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2011-08-12 21:05:31 -0500 |
commit | 078d62b646f3fcecf7918d051472c5905e2957f5 (patch) | |
tree | 435423b561db5f9fc560da0781a2964042f334ac /examples | |
parent | 1cc474786194555bec47dd5c061c1bcc5d992952 (diff) |
keygen example
Diffstat (limited to 'examples')
-rw-r--r-- | examples/keygen.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/keygen.hs b/examples/keygen.hs new file mode 100644 index 0000000..65c3e33 --- /dev/null +++ b/examples/keygen.hs | |||
@@ -0,0 +1,43 @@ | |||
1 | import System.Time (getClockTime, ClockTime(..)) | ||
2 | import qualified Data.Map as Map | ||
3 | import qualified Data.ByteString.Lazy as LZ | ||
4 | |||
5 | import Data.Binary | ||
6 | import OpenSSL.RSA | ||
7 | import Control.Arrow (second) | ||
8 | import Codec.Encryption.RSA.NumberTheory (extEuclGcd) | ||
9 | |||
10 | import qualified Data.OpenPGP as OpenPGP | ||
11 | import qualified Data.OpenPGP.Crypto as OpenPGP | ||
12 | |||
13 | main :: IO () | ||
14 | main = do | ||
15 | time <- getClockTime | ||
16 | let TOD t _ = time | ||
17 | |||
18 | nkey <- generateRSAKey' 1042 65537 | ||
19 | |||
20 | let secretKey = OpenPGP.SecretKeyPacket { | ||
21 | OpenPGP.version = 4, | ||
22 | OpenPGP.timestamp = fromIntegral t, | ||
23 | OpenPGP.key_algorithm = OpenPGP.RSA, | ||
24 | OpenPGP.key = Map.fromList $ map (second OpenPGP.MPI) | ||
25 | [('n', rsaN nkey), ('e', rsaE nkey), | ||
26 | ('d', rsaD nkey), ('p', rsaP nkey), ('q', rsaQ nkey), | ||
27 | ('u', fst $ extEuclGcd (rsaP nkey) (rsaQ nkey))], | ||
28 | OpenPGP.s2k_useage = 0, | ||
29 | OpenPGP.symmetric_type = undefined, | ||
30 | OpenPGP.s2k_type = undefined, | ||
31 | OpenPGP.s2k_hash_algorithm = undefined, | ||
32 | OpenPGP.s2k_salt = undefined, | ||
33 | OpenPGP.s2k_count = undefined, | ||
34 | OpenPGP.encrypted_data = undefined, | ||
35 | OpenPGP.private_hash = undefined } | ||
36 | |||
37 | let userID = OpenPGP.UserIDPacket "Test <test@example.com>" | ||
38 | let message = OpenPGP.Message[ secretKey, userID ] | ||
39 | |||
40 | let message' = OpenPGP.Message [ secretKey, userID, | ||
41 | OpenPGP.sign message message OpenPGP.SHA256 [] (fromIntegral t)] | ||
42 | |||
43 | LZ.putStr $ encode message' | ||