namespace CryptoFile module Tests = open System.Text open System.Security.Cryptography open Crypto let testRSA () = let kpub, kpriv = generateRSAKeysPair let plaintext = "Hello, World!" printfn "plaintext: %A" plaintext let cipherdata = encryptRSA kpub (Encoding.UTF8.GetBytes plaintext) printfn "cipherdata: (size: %A) %A" cipherdata.Length cipherdata let decryptedData = decryptRSA kpriv cipherdata let decryptedText = Encoding.UTF8.GetString decryptedData printfn "decryptedtext: %A" decryptedText assert (plaintext = decryptedText) printfn "testRSA OK" let testRSASignature () = let kpub, kpriv = generateRSAKeysPair let plaintext = "Hello, World!" let sha256 = new SHA256Managed () let signature = signRSA kpriv (sha256.ComputeHash (Encoding.UTF8.GetBytes plaintext)) assert verifySignRSA kpub (sha256.ComputeHash (Encoding.UTF8.GetBytes plaintext)) signature assert not (verifySignRSA kpub (sha256.ComputeHash (Encoding.UTF8.GetBytes "Hello!")) signature) printfn "testRSASignature OK" let runAllTests () = testRSA () testRSASignature ()