1
module CryptoFileTests.Main
8 printfn
"%s [ tests | encrypt <in file> <out file> | decrypt <in file> <out dir> ]\n\
9 \ttests: Run some tests to valid the 'CryptoFile' assembly\n\
10 \tencrypt: Encrypt a file <in> to <out>\n\
11 \tdecrypt: Decrypt a file <in> to <out>" System.AppDomain.CurrentDomain.FriendlyName
13 // Module to store and retreive the keys to and from a file.
14 // The private keys are stored in plain file! Do not let anyone access these files!
15 module internal Keys =
16 // Try to read the public key and private key from files. If one of a file doesn't exist
17 // a new key pair is created, stored then returned.
18 let getKey (filenamePub
: string) (filenamePriv
: string) : Key * Key =
20 use srPub = new StreamReader (filenamePub
)
21 use srPriv = new StreamReader (filenamePriv
)
22 srPub.ReadToEnd (), srPriv.ReadToEnd ()
25 use swPub = new StreamWriter (filenamePub
)
26 use swPriv = new StreamWriter (filenamePriv
)
27 let keyPub, keyPriv
= API.generatKeysPair
()
32 let getSig : Key * Key = getKey "keys-sign.pub" "keys-sign.priv"
33 let getCrypt : Key * Key = getKey "keys-crypt.pub" "keys-crypt.priv"
37 let keySigPub, keySigPriv
= Keys.getSig
38 let keyCryptPub, keyCryptPriv
= Keys.getCrypt
41 | [| "tests" |] -> Tests.doSomeTests
()
42 | [| "encrypt"; input
; output
|] -> API.encryptFile
input output
keySigPriv keyCryptPub
43 | [| "decrypt"; input; outputDir
|] -> API.decryptFile
input outputDir
keySigPub keyCryptPriv