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


C# Crypto.Encrypt方法代码示例

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


在下文中一共展示了Crypto.Encrypt方法的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: Encrypt

        public static string Encrypt(string string_to_encrypt)
        {
            //I noticed a lot of this unable to encrypt message in the logs, I figured it would be best to silence this
            if (String.IsNullOrEmpty(string_to_encrypt)) return "";

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

示例5: AESEncryption

        public string AESEncryption(string plain, string key, bool fips) //Encryption for Settings.DAT
        {
            Crypto superSecret = new Crypto(new AesEngine(), _encoding);
            superSecret.SetPadding(_padding);
            return superSecret.Encrypt(plain, key);

        }
开发者ID:dereklholder,项目名称:OEHP-WPF-Rework,代码行数:7,代码来源:MainWindow.xaml.cs

示例6: Main

    public static void Main(string[] args)
    {
        string serverHost;
        int serverPort;
        int httpPort;
        int payloadSize;
        int uint16Size = 2;
        int uint32Size = 4;
        int packetSize;
        uint cmdId = 1;
        uint seq = 100;
        uint stopSymbol = 1550998638;
        byte[] msg;
        byte[] packet;

        Console.WriteLine("Enter server host name:");

        serverHost = Console.ReadLine();

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

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

        var request = (HttpWebRequest)WebRequest.Create("http://" + serverHost + ":" + 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 hstream = request.GetRequestStream();
                hstream.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 TCP server port number:");

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

        TcpClient client = new TcpClient(serverHost, serverPort);
        NetworkStream stream = client.GetStream();

        msg = Encoding.UTF8.GetBytes("{ \"message\":\"Hello\"}");

        // 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);

        // encrypt
        msg = crypto.Encrypt(msg);

        // create gracenode RPC command packet
        payloadSize = IPAddress.HostToNetworkOrder(msg.Length);
        byte[] payloadSizeBytes = BitConverter.GetBytes(payloadSize);
        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
//.........这里部分代码省略.........
开发者ID:voltrue2,项目名称:gracenode,代码行数:101,代码来源:Tcp.cs

示例7: EncryptData

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

示例8: 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

示例9: 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

示例10: EncryptButton_Click

 private void EncryptButton_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.Encrypt(InputBox.Text);
     }
 }
开发者ID:Thunderpancake,项目名称:xor-encryption-wfa,代码行数:12,代码来源:Form1.cs

示例11: EncryptFileButton_Click

 private void EncryptFileButton_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(KeyBoxFile.Text) || string.IsNullOrWhiteSpace(FilePathBox.Text))
     {
         MessageBox.Show("You must enter a key!");
     }
     else
     {
         ResultsTextBox.AppendText("Encrypting...\n");
         var crypto = new Crypto(KeyBoxFile.Text);
         string fileContents;
         using (StreamReader sr = new StreamReader(FilePathBox.Text))
         {
             fileContents = sr.ReadToEnd();
         }
         using (
                 StreamWriter sw =
                     new StreamWriter(Path.Combine(Path.GetDirectoryName(FilePathBox.Text),
                             Path.GetFileNameWithoutExtension(FilePathBox.Text) + "Encrypted" + ".txt")))
         {
             sw.Write(crypto.Encrypt(fileContents));
             sw.Write(Hasher.GenerateBase64Hash(MD5.Create(), fileContents));
         }
         ResultsTextBox.AppendText("Encryption complete.\n");
     }
 }
开发者ID:Thunderpancake,项目名称:xor-encryption-wfa,代码行数:26,代码来源:Form1.cs

示例12: Encrypt

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

示例13: 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

示例14: EmptyString

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

示例15: FastMicroEncrypt

 public static string FastMicroEncrypt(string src)
 {
     Crypto c = new Crypto(CryptoTypes.encTypeTripleDES);
     c.mCompactCompatible = true;
     return c.Encrypt(src);
 }
开发者ID:mariocosmi,项目名称:Worker,代码行数:6,代码来源:Crypto.cs


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