F
Franz
I use the RC2EncrytoServiceProvider, after encrypted the data, what things should I send in order to let the client who received the
encrypted data to decrypt it?
Thanks.
The following is the code that I encrypt the data.
// Read Data to Byte Array
BinaryReader aByteReader = new BinaryReader(new FileStream(strOriFilePath, FileMode.Open));
int iByteArrayLength = (int)aByteReader.BaseStream.Length;
byte[] byteContent = aByteReader.ReadBytes(iByteArrayLength);
aByteReader.Close();
FileStream aStream = new FileStream(strModFilePath, FileMode.Create);
RC2CryptoServiceProvider aRC2CSP = new RC2CryptoServiceProvider();
aRC2CSP.GenerateKey();
aRC2CSP.GenerateIV();
// Get the Key and IV.
byte[] aKey = aRC2CSP.Key;
byte[] aIV = aRC2CSP.IV;
ICryptoTransform aEncryptor = aRC2CSP.CreateEncryptor(aKey, aIV);
CryptoStream aCryptoStream = new CryptoStream(aStream, aEncryptor, CryptoStreamMode.Write);
aCryptoStream.Write(byteContent, 0, iByteArrayLength);
aCryptoStream.Close();
aStream.Close();
encrypted data to decrypt it?
Thanks.
The following is the code that I encrypt the data.
// Read Data to Byte Array
BinaryReader aByteReader = new BinaryReader(new FileStream(strOriFilePath, FileMode.Open));
int iByteArrayLength = (int)aByteReader.BaseStream.Length;
byte[] byteContent = aByteReader.ReadBytes(iByteArrayLength);
aByteReader.Close();
FileStream aStream = new FileStream(strModFilePath, FileMode.Create);
RC2CryptoServiceProvider aRC2CSP = new RC2CryptoServiceProvider();
aRC2CSP.GenerateKey();
aRC2CSP.GenerateIV();
// Get the Key and IV.
byte[] aKey = aRC2CSP.Key;
byte[] aIV = aRC2CSP.IV;
ICryptoTransform aEncryptor = aRC2CSP.CreateEncryptor(aKey, aIV);
CryptoStream aCryptoStream = new CryptoStream(aStream, aEncryptor, CryptoStreamMode.Write);
aCryptoStream.Write(byteContent, 0, iByteArrayLength);
aCryptoStream.Close();
aStream.Close();