How to symmetric encrypt a file in F#?
-
Wednesday, February 29, 2012 1:48 AMHow to symmetric encrypt a file in F# for tcp transmission?
- Edited by 沈世鈞 Wednesday, February 29, 2012 1:48 AM
All Replies
-
Wednesday, February 29, 2012 9:25 AM
As in any of the MSDN examples for System.Security.Cryptography
Transposing this example to F# should be fairly trivial.
Key exchange is, as always, something that the system design needs to specify, not random people on a forum.
-
Wednesday, February 29, 2012 9:52 AM
would like to specify the password (key)
but password is not the valid size for this algorithm,
tried to
aesCSP.KeySize <- 8
but also same error
let aesCSP = new AesCryptoServiceProvider();
aesCSP.Key <- encoding.GetBytes("shanshan")
//aesCSP.GenerateKey();
aesCSP.GenerateIV();
assume there is no third party to tell the key, how to set the key itself- Edited by 沈世鈞 Wednesday, February 29, 2012 9:54 AM
-
Wednesday, February 29, 2012 10:11 AM
solved by Rfc2898DeriveBytes
- Edited by 沈世鈞 Wednesday, February 29, 2012 10:12 AM
-
Wednesday, February 29, 2012 10:18 AM
The input data is not a complete block.
what does this error mean?
let rec mainLoop (stream: NetworkStream) (msg: string) = ... if !processing = true && msg.StartsWith("start") = false && msg.StartsWith("end") = false then try let encoding=new System.Text.UTF8Encoding() let decryptedmsg = DecryptBytes(this.aesCSP, encoding.GetBytes(msg)) filepacket := !filepacket & decryptedmsg with | ex -> Console.WriteLine(ex.Message.ToString())
member this.aesCSP with get() = let encoding=new System.Text.UTF8Encoding() let AesCSP = new AesCryptoServiceProvider(); //create the initial salt let salt = Encoding.Default.GetBytes("shanshan"); //create the key generator let keyGenerator = new Rfc2898DeriveBytes("demo", salt); //create the secret key 128-bit long let key = keyGenerator.GetBytes(16); AesCSP.Key <- key AesCSP.GenerateIV() AesCSP

