示例#1
0
		/// <summary>
		///		Дешифровка сообщения
		/// </summary>
		/// <param name="message">Сообщение фотмата CMS</param>
		/// <returns>Расшифрованная строка</returns>
		public string Descrypt(CmsMessage message) {
			if (CaConfig == null) {
				throw new Exception("Not initialized");
			}
			if (string.IsNullOrWhiteSpace(message.EncryptedMessage)) {
				throw new ArgumentException("Empty message");
			}
			var provider = new CaProvider();
			provider.Initialize(CaConfig);
			var realMsg = RefineMessage(message);
			var crtPath = provider.GetUserCertPath(message.CertificateFingerprint);
			var keyPath = provider.GetUserKeyPath(message.CertificateFingerprint);
			var cmsPath = Path.GetTempFileName();
			File.WriteAllText(cmsPath, realMsg);
			var arguments = string.Format("smime -decrypt -in {0} -recip {1} -inkey {2} -inform PEM", cmsPath, crtPath, keyPath);
			var startInfo = new ProcessStartInfo {
				FileName = CaConst.OpenSslProcess,
				Arguments = arguments,
				CreateNoWindow = true,
				RedirectStandardOutput = true,
				RedirectStandardError = true,
				UseShellExecute = false
			};
			var process = new Process {StartInfo = startInfo};
			process.Start();
			var output = process.StandardOutput.ReadToEnd();
			process.WaitForExit();
			File.Delete(cmsPath);
			return output;
		}
示例#2
0
        /// <summary>
        ///		Дешифровка сообщения
        /// </summary>
        /// <param name="message">Сообщение фотмата CMS</param>
        /// <returns>Расшифрованная строка</returns>
        public string Descrypt(CmsMessage message)
        {
            if (CaConfig == null)
            {
                throw new Exception("Not initialized");
            }
            if (string.IsNullOrWhiteSpace(message.EncryptedMessage))
            {
                throw new ArgumentException("Empty message");
            }
            var provider = new CaProvider();

            provider.Initialize(CaConfig);
            var realMsg = RefineMessage(message);
            var crtPath = provider.GetUserCertPath(message.CertificateFingerprint);
            var keyPath = provider.GetUserKeyPath(message.CertificateFingerprint);
            var cmsPath = Path.GetTempFileName();

            File.WriteAllText(cmsPath, realMsg);
            var arguments = string.Format("smime -decrypt -in {0} -recip {1} -inkey {2} -inform PEM", cmsPath, crtPath, keyPath);
            var startInfo = new ProcessStartInfo {
                FileName               = CaConst.OpenSslProcess,
                Arguments              = arguments,
                CreateNoWindow         = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                UseShellExecute        = false
            };
            var process = new Process {
                StartInfo = startInfo
            };

            process.Start();
            var output = process.StandardOutput.ReadToEnd();

            process.WaitForExit();
            File.Delete(cmsPath);
            return(output);
        }