Create a new instance of the CipherData class using CipherReference information. : Encryption « Security « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Security » Encryption 
35.14.4.Create a new instance of the CipherData class using CipherReference information.
using System;
using System.Security.Cryptography.Xml;
using System.Xml;
using System.IO;

    class Sample1
    {
        [STAThread]
        static void Main(string[] args)
        {
            String uri = "http://www.yourdomain.com/document.xml";
            Transform base64 = new XmlDsigBase64Transform();
            TransformChain tc = new TransformChain();
            tc.Add(base64);
            CipherReference reference = new CipherReference(uri, tc);
            CipherData cd = new CipherData(reference);

            EncryptedData ed = new EncryptedData();

            ed.Id = "ED";
            ed.EncryptionMethod = new EncryptionMethod("http://www.w3.org/2001/04/xmlenc#aes128-cbc");
            ed.CipherData = cd;

            KeyInfo ki = new KeyInfo();
            ki.AddClause(new KeyInfoRetrievalMethod("#EK""http://www.w3.org/2001/04/xmlenc#EncryptedKey"));
            ed.KeyInfo = ki;

            XmlDocument doc = new XmlDocument();
            XmlElement encryptionPropertyElement = (XmlElement)doc.CreateElement("EncryptionProperty", EncryptedXml.XmlEncNamespaceUrl);
            EncryptionProperty ep = new EncryptionProperty(encryptionPropertyElement);
            ed.AddProperty(ep);

            try{
                string path = @"c:\MyTest.xml";
                File.WriteAllText(path, ed.GetXml().OuterXml);
            }
            catch (IOException e)
            {
                Console.WriteLine("File IO error. {0}", e);
            }
        }
    }
35.14.Encryption
35.14.1.Symmetric Encryption
35.14.2.PublicKey Cryptography
35.14.3.Secret Key Cryptography: RijndaelManaged
35.14.4.Create a new instance of the CipherData class using CipherReference information.
35.14.5.Use DataReference to encrypt and decrypt multiple XML elements using different session keys.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.