Click here to Skip to main content
15,920,596 members
Home / Discussions / C#
   

C#

 
GeneralEmbedded OCX Pin
kroczek5-Mar-03 4:48
kroczek5-Mar-03 4:48 
GeneralRe: Embedded OCX Pin
Stephane Rodriguez.5-Mar-03 4:55
Stephane Rodriguez.5-Mar-03 4:55 
Questionanyone heard Light-Weight Object in c#? Pin
henrykao4-Mar-03 15:26
henrykao4-Mar-03 15:26 
AnswerRe: anyone heard Light-Weight Object in c#? Pin
Stephane Rodriguez.5-Mar-03 6:50
Stephane Rodriguez.5-Mar-03 6:50 
GeneralRe: anyone heard Light-Weight Object in c#? Pin
henrykao5-Mar-03 15:27
henrykao5-Mar-03 15:27 
GeneralHelp with Email and Encryption Pin
tbollers4-Mar-03 8:32
tbollers4-Mar-03 8:32 
GeneralRe: Help with Email and Encryption Pin
Furty4-Mar-03 18:54
Furty4-Mar-03 18:54 
GeneralRe: Help with Email and Encryption Pin
tbollers5-Mar-03 9:57
tbollers5-Mar-03 9:57 
The following is the source code that I wrote to set up my encryption class. This works independently of the entire program and will successfully encrypt and decrypt any byte array I pass through it. However, when I encrypt a file attach it to an email and then decrypt that file when recieved. I lose the data.


using System;
using System.Security.Cryptography;
using System.IO;
using System.Text;
namespace crypt.Cryptography
{

class SymCryptography
{
private string _Key;
public SymCryptography()
{
}

public string EncryptionKey
{
get
{
return _Key;
}
set
{
_Key = value;
}
}

public byte[] Encrypt(byte[] source)
{
byte[] EncryptedFile= null;
byte[] encryptedKey = this.getKeyBytes();
SymmetricAlgorithm rijn =SymmetricAlgorithm.Create();
//Creates the default implementation, which is
//RijndaelManaged.
MemoryStream encryptContainerMS = new MemoryStream();
CryptoStream encryptStream = new CryptoStream
(encryptContainerMS,rijn.CreateEncryptor(encryptedKey,
encryptedKey),CryptoStreamMode.Write);
encryptStream.Write(source,0,source.Length);
encryptStream.FlushFinalBlock();
encryptStream.Close();
EncryptedFile = encryptContainerMS.ToArray();
return EncryptedFile;
}

private byte[] getKeyBytes()
{
UnicodeEncoding UE = new UnicodeEncoding();
return UE.GetBytes(this._Key);
}

public byte[] Decrypt(byte[] source)
{
byte[] DecryptedFile= null;
byte[] encryptedKey = this.getKeyBytes();
SymmetricAlgorithm rijn= SymmetricAlgorithm.Create();
//Creates the default implementation, which is
// RijndaelManaged.
MemoryStream decryptContainer = new MemoryStream();
CryptoStream decryptStream = new CryptoStream(decryptContainer,
rijn.CreateDecryptor(encryptedKey, encryptedKey),
CryptoStreamMode.Write);
decryptStream.Write(source,0,source.Length);
decryptStream.FlushFinalBlock();
decryptStream.Close();
DecryptedFile = decryptContainer.ToArray();
return DecryptedFile;
}

}

}



thanks for the help.
Trevor
GeneralBewitching Windows XP's Insides! Pin
antoine@orchus-tech4-Mar-03 4:56
antoine@orchus-tech4-Mar-03 4:56 
GeneralRe: Bewitching Windows XP's Insides! Pin
Stephane Rodriguez.4-Mar-03 8:24
Stephane Rodriguez.4-Mar-03 8:24 
GeneralRe: Bewitching Windows XP's Insides! Pin
Nnamdi Onyeyiri4-Mar-03 8:45
Nnamdi Onyeyiri4-Mar-03 8:45 
GeneralDataGrid cell Selection & Text selection Pin
stone1984-Mar-03 4:50
stone1984-Mar-03 4:50 
GeneralUsing XML files as a database Pin
TeaTime4-Mar-03 3:33
TeaTime4-Mar-03 3:33 
GeneralRe: Using XML files as a database Pin
Mark Sanders4-Mar-03 9:50
Mark Sanders4-Mar-03 9:50 
GeneralRe: Using XML files as a database Pin
Nick Parker4-Mar-03 18:56
protectorNick Parker4-Mar-03 18:56 
QuestionMultiple Forms: Hot to get Keyboard Input from any form and any Control? Pin
STW4-Mar-03 2:38
STW4-Mar-03 2:38 
GeneralDeleting a row from a datagrid Pin
Yann CK3-Mar-03 23:54
Yann CK3-Mar-03 23:54 
GeneralRe: Deleting a row from a datagrid Pin
Adam Turner5-Mar-03 12:57
Adam Turner5-Mar-03 12:57 
GeneralAccesinng IPHLPAPI.DLL GetNetworkParams() from C# Pin
Member 2680673-Mar-03 22:29
Member 2680673-Mar-03 22:29 
GeneralWindows XP and Many Many Windows Pin
Adam Turner3-Mar-03 21:29
Adam Turner3-Mar-03 21:29 
GeneralProvideProperty for event property Pin
jclanz3-Mar-03 21:10
jclanz3-Mar-03 21:10 
GeneralData Grid doubt Pin
Smitha Nishant3-Mar-03 19:51
protectorSmitha Nishant3-Mar-03 19:51 
GeneralRe: Data Grid doubt Pin
Peter Kiss4-Mar-03 0:34
Peter Kiss4-Mar-03 0:34 
GeneralRe: Data Grid doubt Pin
A.Wegierski4-Mar-03 0:34
A.Wegierski4-Mar-03 0:34 
GeneralRe: Data Grid doubt - Thanks Pin
Smitha Nishant4-Mar-03 4:21
protectorSmitha Nishant4-Mar-03 4:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.