public override void Create(byte[] originalData, SecureEnvelope envelope)
 {
     //create signature
     byte[] signedData = rsaProvider.SignData(originalData, new SHA1Managed());
     //insert digital signature in secure envelope
     envelope.Sections.Add(typeof(NonRepudiationAttribute).ToString(), new NonRepudiationSection(originalData, signedData));
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //An instance of ContractNoteInfo is created.
            ContractNoteInfo noteInfo = new ContractNoteInfo("MSFT", 100, 24);

            //ContractNoteInfo is decorated with Serializable attribute,
            //so the entire object graph with help of BinaryFormatter is
            //flattened into raw bytes and this task is achieved by
            //with help of SerializeContractNote method
            byte[] data = SerializeContractNote(noteInfo);
            //Generate public and private key for demonstration purpose
            GenerateKey();
            //Security Framework is initialized and a new instance of DataSecurity
            //is created and this instance returned by DataSecurityManager
            //is exclusively meant for instances of ContractNoteInfo. This
            //behavior is similar to XmlSerializer where there exists strong
            //coupling between an object instance and the type associated with it.
            DataSecurityManager secMgr  = new DataSecurityManager();
            DataSecurity        dataSec = secMgr.Secure(typeof(ContractNoteInfo));
            //The serialized byte array of ContractNoteInfo is then passed to
            //Create method of DataSecurity that is then handed internally to
            //NonRepudiationProvider which creates digital signature and
            //associates it with SecureEnvelope.  Also, secure envelope itself
            //is marked serializable so its entire object graph itself can now
            //be serialized and transmitted over wire.
            SecureEnvelope secureEnvelope = dataSec.Create(data);

            Console.WriteLine("Secure Envelope successfully created..");
            Console.ReadLine();
        }
        public override bool Verify(SecureEnvelope envelope)
        {
            //extract digital signature from secure envelope
            NonRepudiationSection nonrepSection = envelope.Sections[typeof(NonRepudiationAttribute).ToString()] as NonRepudiationSection;

            //verify digital signature
            return(rsaProvider.VerifyData(nonrepSection.Signature, new SHA1Managed(), nonrepSection.Data));
        }
        public SecureEnvelope Create(byte[] data)
        {
            //Create a new secure envelope
            SecureEnvelope envelope = new SecureEnvelope(profInfo.ProfileName);

            //Based on attribute declared, we instantiate
            //appropriate provider
            if (isNonRepudiation == true)
            {
                nonrepProvider.Create(data, envelope);
            }
            return(envelope);
        }
 public bool Verify(SecureEnvelope envelope)
 {
     //invoke the appropriate provider to verify data
     return(nonrepProvider.Verify(envelope));
 }
 //crytographic transformaton of incoming data
 public abstract bool Verify(SecureEnvelope envelope);
 //crytographic transformaton of outgoing data
 public abstract void Create(byte[] originalData, SecureEnvelope envelope);