/// <summary>
        /// A helper method of to decrypt stream for a specific
        /// remoting call.
        /// </summary>
        /// <param name="identity">call identity</param>
        /// <param name="sinkType">sink type, either server sink or client sink</param>
        /// <param name="transportHeaders">ITransportHeaders object</param>
        /// <param name="targetStream">stream to be decrypted.</param>
        /// <returns>decrypted stream</returns>
        public Stream DecryptStream(string identity, string sinkType, ITransportHeaders transportHeaders, Stream targetStream)
        {
            byte[] key;
            byte[] iv;
            byte[] signature;
            Stream decryptedStream = null;

            string profileName = cc.GetProfileNameByIdentity(identity, "Decrypt", sinkType);

            //perform the data encryption on request
            if (cc.CheckIfSymmatric(profileName))
            {
                //decrypt the stream.
                decryptedStream = Decryption.Decrypt(targetStream, profileName);
            }
            else
            {
                //retrieve addtional information from the transport headers.
                key       = ConvertStringToBytes(transportHeaders["key"].ToString());
                iv        = ConvertStringToBytes(transportHeaders["iv"].ToString());
                signature = ConvertStringToBytes(transportHeaders["signature"].ToString());
                //decrypt the stream
                decryptedStream = Decryption.Decrypt(targetStream, profileName, key, iv, signature);
            }
            return(decryptedStream);
        }
Exemple #2
0
        /// <summary>
        /// decrypt the string data symmetrically using the security profile
        /// information stored in the configuration file
        /// </summary>
        /// <param name="data">encrypted string data</param>
        /// <param name="profile">security profile name</param>
        /// <returns>decrypted string</returns>
        public static string Decrypt(string data, string profile)
        {
            //convert the string to stream
            MemoryStream original        = new MemoryStream(Encoding.Default.GetBytes(data));
            Stream       decryptedStream = Decryption.Decrypt(original, profile);

            byte[] decryptedData = new Byte[decryptedStream.Length];
            decryptedStream.Read(decryptedData, 0, decryptedData.Length);
            //convert the stream to  string
            return(Encoding.Default.GetString(decryptedData));
        }