当前位置: 首页>>代码示例>>C#>>正文


C# Crypto.Decrypt方法代码示例

本文整理汇总了C#中Crypto.Decrypt方法的典型用法代码示例。如果您正苦于以下问题:C# Crypto.Decrypt方法的具体用法?C# Crypto.Decrypt怎么用?C# Crypto.Decrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypto的用法示例。


在下文中一共展示了Crypto.Decrypt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FunkyPasswords

		public void FunkyPasswords() {
			Crypto c = new Crypto();
			{
				const string source = "antonida";
				string s = c.Encrypt(source);
				Assert.AreNotEqual(source, s);
				Assert.AreEqual(source, c.Decrypt(s));
			}
			{
				const string source = "привет мир";
				string s = c.Encrypt(source);
				Assert.AreNotEqual(source, s);
				Assert.AreEqual(source, c.Decrypt(s));
			}
			{
				const string source = @">rL`Fpbgr>_1j^?];cK5U>/!fm;&736puCLZeql=b-,-}rOdeR";
				string s = c.Encrypt(source);
				Assert.AreNotEqual(source, s);
				Assert.AreEqual(source, c.Decrypt(s));
			}
			{
				for (int i = 0; i < 1000; i++) {
					string source = RandomString(Math.Min(i + 1, 50));
					string s = c.Encrypt(source);
					Assert.AreNotEqual(source, s);
					Assert.AreEqual(source, c.Decrypt(s));
				}
			}
		}
开发者ID:TargetProcess,项目名称:Tp.Integration.Ide.VisualStudio,代码行数:29,代码来源:CryptoTest.cs

示例2: UseCustomKey

		public void UseCustomKey() {
			const string S = "WqJCvfqa6JKiSXFm6t9MSAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";

			Crypto c = new Crypto("my secret key");
			string s = c.Encrypt("hello world");
			Assert.AreNotEqual("hello world", s);
			Assert.AreEqual("hello world", c.Decrypt(s));
			Assert.AreEqual("hello world", c.Decrypt(S));
		}
开发者ID:TargetProcess,项目名称:Tp.Integration.Ide.VisualStudio,代码行数:9,代码来源:CryptoTest.cs

示例3: TestEncryptionAES

        public void TestEncryptionAES()
        {
            var c = new Crypto();
            string userKey = "4b236698-ebbb-4d3d-9513-961c5603d431";
            string keySalt = "0000000001";
            string text = "hello";
            string cypher = c.Encrypt(text, userKey, keySalt);
            Console.WriteLine(cypher);

            string textdec = c.Decrypt(cypher, userKey, keySalt);
            Assert.AreEqual(text, textdec);
        }
开发者ID:Horndev,项目名称:Bitcoin-Exchange-APIs.NET,代码行数:12,代码来源:TestKrakenCrypto.cs

示例4: DecryptButton_Click

 private void DecryptButton_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(KeyBox.Text))
     {
         MessageBox.Show("You must enter a key!");
     }
     else
     {
         var crypto = new Crypto(KeyBox.Text);
         OutputBox.Text = crypto.Decrypt(InputBox.Text);
     }
 }
开发者ID:Thunderpancake,项目名称:xor-encryption-wfa,代码行数:12,代码来源:Form1.cs

示例5: Decrypt

        public static string Decrypt(string string_to_decrypt)
        {
            if (string.IsNullOrWhiteSpace(string_to_decrypt)) return string.Empty;

            try
            {
                Crypto c = new Crypto(Crypto.CryptoTypes.encTypeTripleDES);
                return c.Decrypt(string_to_decrypt);
            }
            catch (Exception ex)
            {
                LogHelper.logError("Security.cs", "Unable to decrypt " + string_to_decrypt + " " + ex.Message + " " + ex.StackTrace);
                return "";
            }
        }
开发者ID:hobbe5,项目名称:LeanerSnow,代码行数:15,代码来源:Security.cs

示例6: OnAuthorization

        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (!filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
            {
                // ?token=XtsMJRrUtGiytKZ2b6H0eBgVzfNS5hr73kapmZiA4GDENdrRNRXSlis7BFrp4mtr
                string tokenStatus = "ok";
                string token = "";

                if (HttpContext.Current.Request["token"] != null)
                {
                    string encryptedToken = HttpContext.Current.Request["token"].ToString();
                    try
                    {
                        Crypto crypto = new Crypto(true);
                        token = crypto.Decrypt(HttpContext.Current.Server.HtmlEncode(encryptedToken));
                        char[] spaceSeparator = { ' ' };
                        string[] a = token.Split(spaceSeparator);
                        var timestamp = new DateTime(long.Parse(a[0]));
                        if (timestamp.AddMinutes(120) < DateTime.Now)
                        {
                            tokenStatus = "Expired token";
                            token = "";
                        }
                        else
                            HttpContext.Current.Session["token"] = token;
                    }
                    catch (Exception ex)
                    {
                        tokenStatus = ex.Message;
                    }
                }
                else
                {
                    if (HttpContext.Current.Session["token"] != null)
                        token = HttpContext.Current.Session["token"].ToString();
                    else
                        tokenStatus = "Missing token";
                }

                if (tokenStatus != "ok")
                {
                    filterContext.Result = new RedirectToRouteResult(
                        new RouteValueDictionary { { "action", "Index" }, { "controller", "Unauthorized" }, { "tokenStatus", tokenStatus } }
                    );
                }
            }
        }
开发者ID:ssaporta,项目名称:reports,代码行数:47,代码来源:Authentication.cs

示例7: DecryptFileButton_Click

 private void DecryptFileButton_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(KeyBoxFile.Text) || string.IsNullOrWhiteSpace(FilePathBox.Text))
     {
         MessageBox.Show("You must enter a key!");
     }
     else
     {
         ResultsTextBox.AppendText("Decrypting...\n");
         var crypto = new Crypto(KeyBoxFile.Text);
         string fileContents;
         string extractedHash;
         string decryptedHash;
         using (StreamReader sr = new StreamReader(FilePathBox.Text))
         {
             fileContents = sr.ReadToEnd();
         }
         extractedHash = Hasher.ExtractHash(fileContents);
         ExtractedHashBox.Text = extractedHash;
         fileContents = fileContents.Substring(0, fileContents.Length - 24);
         var utf8WithBom = new UTF8Encoding(true);
         using (
                 StreamWriter sw =
                     new StreamWriter(Path.Combine(Path.GetDirectoryName(FilePathBox.Text),
                             Path.GetFileNameWithoutExtension(FilePathBox.Text) + "Decrypted" + ".txt"), false, utf8WithBom))
         {
             sw.Write(crypto.Decrypt(fileContents));
         }
         using (StreamReader sr = new StreamReader(Path.Combine(Path.GetDirectoryName(FilePathBox.Text), Path.GetFileNameWithoutExtension(FilePathBox.Text) + "Decrypted" + ".txt")))
         {
             fileContents = sr.ReadToEnd();
         }
         decryptedHash = Hasher.GenerateBase64Hash(MD5.Create(), fileContents);
         ResultsTextBox.AppendText("Decryption complete.\n");
         ResultsTextBox.AppendText(string.Format("Decrypted Hash: {0}\n", decryptedHash));
         ResultsTextBox.AppendText(string.Format("Extracted Hash: {0}\n", extractedHash));
         if (Hasher.VerifyHash(decryptedHash, extractedHash))
         {
             ResultsTextBox.AppendText("Hashes match!  Successful decryption.\n");
         }
         else
         {
             ResultsTextBox.AppendText("Hashes do not match!  Unsuccessful decryption.\n");
         }
     }
 }
开发者ID:Thunderpancake,项目名称:xor-encryption-wfa,代码行数:46,代码来源:Form1.cs

示例8: Main


//.........这里部分代码省略.........
        packetSize = uint32Size + (uint16Size * 2) + msg.Length + uint32Size;
        packet = new byte[packetSize];

        Console.WriteLine("payload size is {0}", msg.Length);
        Console.WriteLine("packet size is {0}", packetSize);

        // RPC protocol version 0
        packet[0] = 0x0;

        // add payload size at the offset of 0: payload size if utin32 4 bytes
        Buffer.BlockCopy(payloadSizeBytes, 0, packet, 0, uint32Size);

        // add command ID at the offset of 4: command ID is uint16 2 bytes
        byte[] cmd = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short)cmdId));
        Buffer.BlockCopy(cmd, 0, packet, 4, uint16Size);

        // add seq at the offset of 6: seq is uint16 2 bytes
        byte[] seqBytes = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short)seq));
        Buffer.BlockCopy(seqBytes, 0, packet, 6, uint16Size);

        // add payload at the offset of 8
        Buffer.BlockCopy(msg, 0, packet, 8, msg.Length);

        // add magic stop symbol: magic stop symbol is uint 32 4 bytes
        int stop = IPAddress.HostToNetworkOrder(Convert.ToInt32(stopSymbol));
        byte[] stopBytes = BitConverter.GetBytes(stop);
        Buffer.BlockCopy(stopBytes, 0, packet, msg.Length + 8, uint32Size);

        Console.WriteLine("Sending command packet: {0}", packet.Length);

        // send command packet to server
        stream.Write(packet, 0, packet.Length);

        // receive the response back from server
        // read in chunk of 2KB
        byte[] res = new byte[2048];
        int bytesRead = 0;
        bytesRead = stream.Read(res, 0, res.Length);
        while (bytesRead > 0) {
            // read payload size
            byte[] psizeBytes = new byte[uint32Size];
            Buffer.BlockCopy(res, 0, psizeBytes, 0, uint32Size);
            // big endian
            Array.Reverse(psizeBytes);
            uint psize = BitConverter.ToUInt32(psizeBytes, 0);

            Console.WriteLine("Reply payload size is {0}", psize);

            // read reply flag
            byte[] flagBytes = new byte[4];
            Buffer.BlockCopy(res, 4, flagBytes, 0, 1);
            int replyFlag = BitConverter.ToInt32(flagBytes, 0);

            Console.WriteLine("Reply flag is {0}", replyFlag);

            // read reply status
            byte[] statusBytes = new byte[4];
            Buffer.BlockCopy(res, 5, statusBytes, 0, 1);
            int status = BitConverter.ToInt32(statusBytes, 0);

            Console.WriteLine("Replay status is {0}", status);

            // read seq
            byte[] rseqBytes = new byte[uint16Size];
            Buffer.BlockCopy(res, 6, rseqBytes, 0, uint16Size);
            // big endian
            Array.Reverse(rseqBytes);
            uint rseq = BitConverter.ToUInt16(rseqBytes, 0);

            Console.WriteLine("Reply seq is {0}", rseq);

            // read payload
            byte[] payloadBytes = new byte[psize];
            Buffer.BlockCopy(res, 8, payloadBytes, 0, Convert.ToInt32(psize));
            //string payload = Encoding.UTF8.GetString(payloadBytes, 0, payloadBytes.Length);

            Console.WriteLine("Reply payload is {0}", Encoding.UTF8.GetString(crypto.Decrypt(payloadBytes)));

            // read magic stop symbol
            byte[] sbytes = new byte[uint32Size];
            Buffer.BlockCopy(res, 8 + Convert.ToInt32(psize), sbytes, 0, uint32Size);
            // big endian
            Array.Reverse(sbytes);
            uint mstop = BitConverter.ToUInt32(sbytes, 0);

            Console.WriteLine("Magic stop symbol is {0}. must be the same as {1}", mstop, stopSymbol);

            if (mstop == stopSymbol) {
                Console.WriteLine("End of replay packet");
                break;
            }

            bytesRead = stream.Read(res, 0, res.Length);
        }

        Console.WriteLine("Done and close connection");

        // close the connection
        //stream.Close();
    }
开发者ID:voltrue2,项目名称:gracenode,代码行数:101,代码来源:Tcp.cs

示例9: DecryptData

 /// <summary>
 /// Return the decrypted value of the string passed in.
 /// </summary>
 /// <param name="str">The string to decrypt</param>
 /// <returns>The decrypted value of the string.</returns>
 public static string DecryptData(string str)
 {
     if (str == null) return string.Empty;
     Crypto CheckCrypto = new Crypto();
     string result = CheckCrypto.Decrypt(str, false);
     if (result == str || result == null || result == "")
         result = CheckCrypto.Encrypt(str, true);
     return result;
 }
开发者ID:ciswebb,项目名称:FPC-Estimate-App,代码行数:14,代码来源:BaseFormulaUtils.cs

示例10: Decrypt

 /// <summary>
 /// Return the decrypted value of the string passed in.
 /// </summary>
 /// <param name="str">The string to decrypt</param>
 /// <returns>The decrypted value of the string.</returns>
 public static string Decrypt(string str)
 {
     if (str == null) return string.Empty;
     Crypto CheckCrypto = new Crypto();
     return CheckCrypto.Decrypt(str);
 }
开发者ID:ciswebb,项目名称:FPC-Estimate-App,代码行数:11,代码来源:BaseFormulaUtils.cs

示例11: Main

    static void Main(string[] args)
    {
        string serverIp;
        int httpPort;
        int serverPort;
        const string STOP = "stop";

        Console.WriteLine("Enter server IP address:");

        serverIp = Console.ReadLine();

        Console.WriteLine("Enter HTTP port number:");

        httpPort = int.Parse(Console.ReadLine());

        Console.WriteLine("Connection to {0}:{1}", serverIp, httpPort);

        var request = (HttpWebRequest)WebRequest.Create("http://" + serverIp + ":" + httpPort + "/auth");
        var postData = "thing1=hello";
        postData += "&thing2=world";
        var data = Encoding.ASCII.GetBytes(postData);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = data.Length;
        var stream = request.GetRequestStream();
        stream.Write(data, 0, data.Length);
        var response = (HttpWebResponse)request.GetResponse();
        var authRes = new StreamReader(response.GetResponseStream()).ReadToEnd();

        Console.WriteLine("Auth response:{0}", authRes);

        JSONNode auth = JSON.Parse(authRes);

        Console.WriteLine("Session ID is {0}", auth["sessionId"]);
        Console.WriteLine(
            "Cipher Key, Nonce, and MacKey:{0}, {1}, {2}",
            auth["cipherData"]["base64"]["cipherKey"],
            auth["cipherData"]["base64"]["cipherNonce"],
            auth["cipherData"]["base64"]["macKey"]
        );

        Console.WriteLine("Enter UDP server port number:");

        serverPort = int.Parse(Console.ReadLine());

        Console.WriteLine("Connection to {0}:{1}", serverIp, serverPort);

        int myPort = 54061;

        // connect to UDP server and send message
        UdpClient client = new UdpClient(myPort);
        IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(serverIp), serverPort);
        client.Connect(endPoint);

        Console.WriteLine("Prepare encryption");

        // prepare encryption
        Guid sid = new Guid(auth["sessionId"]);
        byte[] cipherKey = System.Convert.FromBase64String(auth["cipherData"]["base64"]["cipherKey"]);
        byte[] cipherNonce = System.Convert.FromBase64String(auth["cipherData"]["base64"]["cipherNonce"]);
        byte[] macKey = System.Convert.FromBase64String(auth["cipherData"]["base64"]["macKey"]);
        var crypto = new Crypto(sid, cipherKey, cipherNonce, macKey);

        byte[] packet = Encoding.ASCII.GetBytes("{\"command\":1,\"payload\":\"Hello\"}");
        var epacket = crypto.Encrypt(packet);

        client.Send(epacket, epacket.Length);

        Console.WriteLine("UDP message sent: size is {0}", epacket.Length);

        Console.WriteLine("Waiting for server message...");

        byte[] recData = client.Receive(ref endPoint);

        Console.WriteLine("Try decrypting...");

        var dpack = crypto.Decrypt(recData);

        Console.WriteLine("message from server: {0}", Encoding.UTF8.GetString(dpack));
    }
开发者ID:voltrue2,项目名称:gracenode,代码行数:80,代码来源:Udp.cs

示例12: AlgorithmCryptographicException

		public void AlgorithmCryptographicException() {
			Crypto c = new Crypto("my secret key");
			c.Decrypt(Convert.ToBase64String(Encoding.UTF8.GetBytes("hello world")));
		}
开发者ID:TargetProcess,项目名称:Tp.Integration.Ide.VisualStudio,代码行数:4,代码来源:CryptoTest.cs

示例13: Decrypt

 public virtual string Decrypt(string Source)
 {
     Crypto CheckCrypto = new Crypto(Crypto.Providers.DES);
     return(CheckCrypto.Decrypt(Source));
 }
开发者ID:ciswebb,项目名称:FPC-Estimate-App,代码行数:5,代码来源:BaseApplicationPage.cs

示例14: RunAs

        /// <summary>
        /// Runs a command with impersonation (new style)
        /// </summary>
        /// <param name="credentials"></param>
        /// <param name="command"></param>
        /// <param name="logger"></param>
        /// <returns></returns>
        public static RunAsResult RunAs(SecurityCredentials credentials, string command)
        {
            var crypto = new Crypto(_s_k, _s_v);
            var pass = crypto.Decrypt(credentials.EncryptedPassword);
            crypto.Dispose();

            using (new Impersonator(credentials.User, credentials.Domain, pass,
                    LogonType.Logon32LogonNewCredentials, LogonProvider.Logon32ProviderWinnt50))
            {
                try
                {
                    var p = new Process();
                    var si = new ProcessStartInfo();
                    si.WorkingDirectory = System.Environment.CurrentDirectory;
                    si.WindowStyle = ProcessWindowStyle.Hidden;
                    si.FileName = "cmd.exe";
                    si.Arguments = @"/c " + command;
                    p.StartInfo = si;
                    p.Start();
                    p.WaitForExit((int)TimeSpan.FromMinutes(180).TotalMilliseconds);

                    return new RunAsResult
                    {
                        ExitCode = p.ExitCode,
                        ProcessId = p.Id
                    };
                }
                catch (Exception)
                {
                    throw new Win32Exception();
                }
            }
        }
开发者ID:pjagga,项目名称:SeleniumMSTestVS2013,代码行数:40,代码来源:WinAPI.cs

示例15: UseDefaultKey

		public void UseDefaultKey() {
			Crypto c = new Crypto();
			string s = c.Encrypt("hello world");
			Assert.AreNotEqual("hello world", s);
			Assert.AreEqual("hello world", c.Decrypt(s));
		}
开发者ID:TargetProcess,项目名称:Tp.Integration.Ide.VisualStudio,代码行数:6,代码来源:CryptoTest.cs


注:本文中的Crypto.Decrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。