Encrypting and decrypting from memory to file (C# example)
In This Topic
C# - Encryption |
Copy Code |
XceedEncryptionLib.XceedEncryption encrypt = new XceedEncryptionLib.XceedEncryptionClass();
encrypt.License( @"your license key" );
XceedEncryptionLib.XceedRijndaelEncryptionMethod rijndael = new XceedEncryptionLib.XceedRijndaelEncryptionMethodClass();
object source = "This is the data to encrypt";
try { rijndael.SetSecretKeyFromPassPhrase( "This is a weak pass phrase", 128 );
encrypt.EncryptionMethod = rijndael;
encrypt.WriteFile( ref source, XceedEncryptionLib.EXEFileProcessing.efpEncrypt, true, @"c:\test\file.enc", false ); } catch( System.Runtime.InteropServices.COMException except ) { MessageBox.Show( except.ToString() ); } |
C# - Decryption |
Copy Code |
XceedEncryptionLib.XceedEncryption encrypt = new XceedEncryptionLib.XceedEncryptionClass();
encrypt.License( @"your license key" );
XceedEncryptionLib.XceedRijndaelEncryptionMethod rijndael = new XceedEncryptionLib.XceedRijndaelEncryptionMethodClass();
try { rijndael.SetSecretKeyFromPassPhrase( "This is a weak pass phrase", 128 );
encrypt.EncryptionMethod = rijndael;
object bytesRead = null; object decryptedData = encrypt.ReadFile( @"c:\test\file.enc", 0, 0, XceedEncryptionLib.EXEFileProcessing.efpDecrypt, true, ref bytesRead );
MessageBox.Show( System.Text.Encoding.Unicode.GetString( ( byte[] )decryptedData ) ); } catch( System.Runtime.InteropServices.COMException except ) { MessageBox.Show( except.ToString() ); } |