Re: Encrypting binary files
Quote:
Originally posted by FaisalJ
Now when the input file is a text file its works ok
but when thefile is a binay file (a Serialized file to be exact)
the outbuf = rsa.Encrypt(inbuf,false); crashes giving the error "bad length"
Assuming that the crash is due to the wrong public key a CryptographicException is thrown.
If you use RSA, you have first to provide the generated public Key, which is used to encrypt the file, after transmission you can decrypt the file. You can forward the generated public key as a string by using
pubKey = rsa.ToXmlString(false);
after providing this key, you use it with
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(publicKey_Client);
-then performing with this pubKey the encryption
-transfer the encrypted byte[]
-decrypt
Hope that helps;)