+// Module to store and retreive the keys to and from a file.
+// The private keys are stored in plain file! Do not let anyone access these files!
+module internal Keys =
+ // Try to read the public key and private key from files. If one of a file doesn't exist
+ // a new key pair is created, stored the returned.
+ let getKey (filenamePub: string) (filenamePriv: string) : Key * Key =
+ try
+ use srPub = new StreamReader (filenamePub)
+ use srPriv = new StreamReader (filenamePriv)
+ srPub.ReadToEnd (), srPriv.ReadToEnd ()
+ with
+ | _ ->
+ use swPub = new StreamWriter (filenamePub)
+ use swPriv = new StreamWriter (filenamePriv)
+ let keyPub, keyPriv = API.generatKeysPair
+ swPub.Write keyPub
+ swPriv.Write keyPriv
+ keyPub, keyPriv
+
+ let getSig : Key * Key = getKey "keys-sign.pub" "keys-sign.priv"
+ let getCrypt : Key * Key = getKey "keys-crypt.pub" "keys-crypt.priv"
+