CabConModding
Facebook
Twitter
youtube
Discord
Contact us
RSS
Menu
CabConModding
Home
New
Top
Premium
Rules
FAQ - Frequently Asked Questions
Games
Fornite
Call of Duty: Black Ops 3
Clash of Clans
Grand Theft Auto 5
Apex Legends
Assassin’s Creed Origins
Forums
Premium
Latest posts
What's new
Latest posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Log in
Register
What's new
Premium
Latest posts
Menu
Log in
Register
Navigation
Install the app
Install
More options
Dark Theme
Contact us
Close Menu
Forums
Tech Boards
Computer Programming
Source Code & Tutorial
[C#] String Encryption using a WebServer
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Harry" data-source="post: 34510" data-attributes="member: 35"><p>So the past few days, I've been helping a few devs remove strings from their tools, to say, stop people getting their webservers IP and messing with their systems. This is not a definitive fix, and bypassing this is easy, BUT, using methods of .NET obfuscation, even if parts of the source are cracked, no strings are there to be tampered with.</p><p></p><p><strong>Things you will need</strong></p><ul> <li data-xf-list-type="ul">Webserver (PHPMyAdmin is optional) - I'm using <a href="http://www.wampserver.com/en/" target="_blank"><span style="color: #0080ff">WAMP</span></a></li> <li data-xf-list-type="ul">Simple knowledge of "bytes"...</li> <li data-xf-list-type="ul">Half a brain (this is a C+P tutorial)</li> </ul><p><strong>Skill Level - <span style="color: #ff0000">Experienced</span></strong></p><p></p><p><strong>Example & Method</strong></p><p>[SPOILER="Getting String from Webserver (Encrypted URL)"]</p><p>Create a file on your webserver, call it what ever you want, but make sure it's a ".txt" file. This file will display a string of bytes and your program will convert this to a byte array, then to a string, and use this string as a "key" to Decrypt all of your future strings. (This will make more sense soon)</p><p></p><p>First, we need to get our link to the file we just created. I am using WAMP, so my URL is "<a href="http://localhost/key.txt" target="_blank">http://localhost/key.txt</a>". We need to convert this to hex. This website is perfect: <a href="https://codebeautify.org/string-hex-converter" target="_blank">https://codebeautify.org/string-hex-converter</a></p><p></p><p>In the top textbox, enter your url (include "http://"), then hit convert.</p><p>My input/output:</p><p>[CODE]Input: http://localhost/key.txt</p><p>Output: 687474703a2f2f6c6f63616c686f73742f6b65792e747874[/CODE]</p><p></p><p>This random letters and numbers are our bytes. We need to convert these to look like this:</p><p>[CODE]0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x6B, 0x65, 0x79, 0x2E, 0x74, 0x78, 0x74[/CODE]</p><p></p><p>Simply split your output into values of two:</p><p>[CODE]68 74 74 70...[/CODE]</p><p>Add a "," after each (don't do this on the last byte):</p><p>[CODE]68, 74, 74, 70,...[/CODE]</p><p>And add "0x" in front of each:</p><p>[CODE]0x68, 0x74, 0x74, 0x70,...[/CODE]</p><p>Do this to all the bytes!</p><p></p><p>Now we have a byte array to our key file on our webserver.</p><p>Now lets place some text into this file, and attempt to display it in a MessageBox.</p><p></p><p>I will put "test" into mine.</p><p></p><p><strong>Double Click your Form</strong></p><p>Include these at the top of your code:</p><p>[CODE]using System.Net;</p><p>using System.Security.Cryptography;[/CODE]</p><p></p><p>We now will create a byte array to our server.</p><p>Place this code inside "Form1_Load":</p><p>[CODE]byte[] myByteArray = { BYTE ARRAY REPLACES THIS TEXT };[/CODE]</p><p>Now we can convert the bytes to text by using this function:</p><p>[CODE]public string BytesToString(byte[] arr)</p><p>{</p><p> return Encoding.UTF8.GetString(arr);</p><p>}[/CODE]</p><p></p><p>Now we will show this in a message using a WebClient.</p><p>Above the "private void Form1_Load(object sender, EventArgs e)" function, place this:</p><p>[CODE]WebClient client = new WebClient();[/CODE]</p><p></p><p>Now place this inside of "Form1_Load":</p><p>[CODE]MessageBox.Show(client.DownloadString(BytesToString(myByteArray)));[/CODE]</p><p></p><p>When you run this, a MessageBox should show and say "test".</p><p>[/SPOILER]</p><p>[SPOILER="String Encryption + Decryption Keys"]</p><p>Now we need to use these two functions in order to Encrypt and Decrypt our strings:</p><p>[CODE]</p><p> string key = "L1$Ba8s!5)g$Sb41";</p><p></p><p> public string Encrypt(string data)</p><p> {</p><p> using (var des = new TripleDESCryptoServiceProvider { Mode = CipherMode.ECB, Key = Encoding.UTF8.GetBytes(key), Padding = PaddingMode.PKCS7 })</p><p> using (var desEncrypt = des.CreateEncryptor())</p><p> {</p><p> var buffer = Encoding.UTF8.GetBytes(data);</p><p></p><p> return Convert.ToBase64String(desEncrypt.TransformFinalBlock(buffer, 0, buffer.Length));</p><p> }</p><p> }</p><p></p><p> public string Decrypt(string data)</p><p> {</p><p> using (var des = new TripleDESCryptoServiceProvider { Mode = CipherMode.ECB, Key = Encoding.UTF8.GetBytes(key), Padding = PaddingMode.PKCS7 })</p><p> using (var desEncrypt = des.CreateDecryptor())</p><p> {</p><p> var buffer = Convert.FromBase64String(data.Replace(" ", "+"));</p><p></p><p> return Encoding.UTF8.GetString(desEncrypt.TransformFinalBlock(buffer, 0, buffer.Length));</p><p> }</p><p> }[/CODE]</p><p></p><p>As you may see, our key string is clearly visible, and anyone who gets this will be able to decrypt our top kek encrypted strings. We will Encrypt this using bytes, and store it on our webserver instead. Make sure to remove your key from your code, once you have chosen a key, make the:</p><p>[CODE]string key = "L1$Ba8s!5)g$Sb41";[/CODE]</p><p>be:</p><p>[CODE]string key;[/CODE]</p><p></p><p>Now, we <strong>have to keep our key 16 characters long</strong>, or it will not work.</p><p>So make a 16 character key and throw it into the string to hex converter website again.</p><p>[CODE]Input: L1$Ba8s!5)g$Sb41</p><p>Output: 4c312442613873213529672453623431[/CODE]</p><p></p><p>We need to convert this to bytes again, but no "," or "0x" this time. My output looks like:</p><p>[CODE]4C 31 24 42 61 38 73 21 35 29 67 24 53 62 34 31[/CODE]</p><p>Now we replace "test" with the bytes above in our key.txt file.</p><p>If we run our program now, we should get a MessageBox with the bytes you have entered.</p><p>Now we want to convert this to be able to use it as our key.</p><p>In Form1_Load, add this:</p><p>[CODE]</p><p>string ourKeyBytes = client.DownloadString(BytesToString(myByteArray));</p><p> byte[] bytes = ourKeyBytes.Split().Select(t => byte.Parse(t, System.Globalization.NumberStyles.AllowHexSpecifier)).ToArray();</p><p> key = BytesToString(bytes);</p><p>[/CODE]</p><p>Now our Encryption has a key, we can Encrypt a string. So lets create another file on our server and call it "test.txt".</p><p></p><p>Under the code we have added in "Form1_Load", add this:</p><p>[CODE]MessageBox.Show(Encrypt("STRING I WANNA ENCRYPT");[/CODE]</p><p>Run the program and make note of the exact characters in the MessageBox... Put these into the string to HEX converter website again.</p><p></p><p>I am Encrypting the string:</p><p>[CODE]ProfoundModz[/CODE]</p><p>When Encrypted, it is:</p><p>[CODE]72JeeVa1RmLbwn0PJVU4RQ==[/CODE]</p><p>Converting this to hex, it becomes:[CODE]37324a6565566131526d4c62776e30504a56553452513d3d[/CODE]</p><p>Now we have to split this again, but only the spaces, no comma or "0x":</p><p>[CODE]37 32 4A 65 65 56 61 31 52 6D 4C 62 77 6E 30 50 4A 56 55 34 52 51 3D 3D[/CODE]</p><p></p><p>Now place this split hex into our "test.txt" file on our webserver, and attempt to retrieve and Decrypt it!</p><p></p><p>Now we will use some of the same byte array as gaining the key in order to get this (same method at least), but instead of "<a href="http://localhost/key.txt" target="_blank">http://localhost/key.txt</a>", we need "<a href="http://localhost/test.txt" target="_blank">http://localhost/test.txt</a>"</p><p>We only need to replace 3 bytes and add one. So our byte array for the key.txt link is:</p><p>[CODE]0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x6B, 0x65, 0x79, 0x2E, 0x74, 0x78, 0x74[/CODE]</p><p></p><p>You may notice the end being: [CODE]0x2E, 0x74, 0x78, 0x74[/CODE]. This is ".txt" in HEX. that must mean the last 7 bytes are "key.txt". From these, will update the first 3, and add one after. I will replace [CODE]0x6B, 0x65, 0x79[/CODE] to [CODE]0x74, 0x65, 0x73, 0x74[/CODE], as this is "test" in hex to bytes.</p><p></p><p>Under the code already in "Form1_Load", remove the MessageBox.Show code, and add a new array: [CODE]byte[] myOtherByteArray = { BYTES HERE };[/CODE]. I will replace "BYTES HERE" with:</p><p>[CODE]0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x74, 0x78, 0x74[/CODE]</p><p></p><p>Now add this under our new byte array:</p><p>[CODE]string myOtherMessageBytes = client.DownloadString(BytesToString(myOtherByteArray));</p><p> byte[] Otherbytes = myOtherMessageBytes.Split().Select(t => byte.Parse(t, System.Globalization.NumberStyles.AllowHexSpecifier)).ToArray();[/CODE]</p><p></p><p>Now we can display the Decrypted text in a MessageBox like so:</p><p>[CODE]MessageBox.Show(Decrypt(BytesToString(Otherbytes)));[/CODE]</p><p>[/SPOILER]</p><p>[SPOILER="Better Ways to do this"]</p><p>I created a program so quickly Encrypt a string and byte it into the byte format (XX XX XX...) for me, and then I put this into a file using ":" between each encrypted string. Then I download it, and split it using ":" into an array, and then I can assign each string that I need to manually. If you'd like me to show you how to do this, PM me, and I'll share some sources.</p><p></p><p>Also consider "downloading" parts of your code (encrypt it like above). I'll make a tutorial on this in the future.</p><p>[/SPOILER]</p><p>[SPOILER="End Tool Source"]</p><p>[CODE]</p><p>using System;</p><p>using System.Collections.Generic;</p><p>using System.ComponentModel;</p><p>using System.Data;</p><p>using System.Drawing;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Threading.Tasks;</p><p>using System.Windows.Forms;</p><p>using System.Net;</p><p>using System.Security.Cryptography;</p><p></p><p>namespace String_Encryption_Tool</p><p>{</p><p> public partial class Form1 : Form</p><p> {</p><p> public Form1()</p><p> {</p><p> InitializeComponent();</p><p> }</p><p></p><p> WebClient client = new WebClient();</p><p> public string BytesToString(byte[] arr)</p><p> {</p><p> return Encoding.UTF8.GetString(arr);</p><p> }</p><p></p><p> string key;</p><p></p><p> public string Encrypt(string data)</p><p> {</p><p> using (var des = new TripleDESCryptoServiceProvider { Mode = CipherMode.ECB, Key = Encoding.UTF8.GetBytes(key), Padding = PaddingMode.PKCS7 })</p><p> using (var desEncrypt = des.CreateEncryptor())</p><p> {</p><p> var buffer = Encoding.UTF8.GetBytes(data);</p><p></p><p> return Convert.ToBase64String(desEncrypt.TransformFinalBlock(buffer, 0, buffer.Length));</p><p> }</p><p> }</p><p></p><p> public string Decrypt(string data)</p><p> {</p><p> using (var des = new TripleDESCryptoServiceProvider { Mode = CipherMode.ECB, Key = Encoding.UTF8.GetBytes(key), Padding = PaddingMode.PKCS7 })</p><p> using (var desEncrypt = des.CreateDecryptor())</p><p> {</p><p> var buffer = Convert.FromBase64String(data.Replace(" ", "+"));</p><p></p><p> return Encoding.UTF8.GetString(desEncrypt.TransformFinalBlock(buffer, 0, buffer.Length));</p><p> }</p><p> }</p><p></p><p> private void Form1_Load(object sender, EventArgs e)</p><p> {</p><p> byte[] myByteArray = { 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x6B, 0x65, 0x79, 0x2E, 0x74, 0x78, 0x74 };</p><p> //MessageBox.Show(client.DownloadString(BytesToString(myByteArray)));</p><p></p><p> string myKeyBytes = client.DownloadString(BytesToString(myByteArray));</p><p> byte[] bytes = myKeyBytes.Split().Select(t => byte.Parse(t, System.Globalization.NumberStyles.AllowHexSpecifier)).ToArray();</p><p> key = BytesToString(bytes);</p><p></p><p> byte[] myOtherByteArray = { 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x74, 0x78, 0x74 };</p><p> string myOtherMessageBytes = client.DownloadString(BytesToString(myOtherByteArray));</p><p> byte[] Otherbytes = myOtherMessageBytes.Split().Select(t => byte.Parse(t, System.Globalization.NumberStyles.AllowHexSpecifier)).ToArray();</p><p></p><p> MessageBox.Show(Decrypt(BytesToString(Otherbytes)));</p><p> </p><p> }</p><p> }</p><p>}[/CODE]</p><p>[/SPOILER]</p><p>~ Harry</p></blockquote><p></p>
[QUOTE="Harry, post: 34510, member: 35"] So the past few days, I've been helping a few devs remove strings from their tools, to say, stop people getting their webservers IP and messing with their systems. This is not a definitive fix, and bypassing this is easy, BUT, using methods of .NET obfuscation, even if parts of the source are cracked, no strings are there to be tampered with. [B]Things you will need[/B] [LIST] [*]Webserver (PHPMyAdmin is optional) - I'm using [URL='http://www.wampserver.com/en/'][COLOR=#0080ff]WAMP[/COLOR][/URL] [*]Simple knowledge of "bytes"... [*]Half a brain (this is a C+P tutorial) [/LIST] [B]Skill Level - [COLOR=#ff0000]Experienced[/COLOR][/B] [B]Example & Method[/B] [SPOILER="Getting String from Webserver (Encrypted URL)"] Create a file on your webserver, call it what ever you want, but make sure it's a ".txt" file. This file will display a string of bytes and your program will convert this to a byte array, then to a string, and use this string as a "key" to Decrypt all of your future strings. (This will make more sense soon) First, we need to get our link to the file we just created. I am using WAMP, so my URL is "[URL]http://localhost/key.txt[/URL]". We need to convert this to hex. This website is perfect: [URL]https://codebeautify.org/string-hex-converter[/URL] In the top textbox, enter your url (include "http://"), then hit convert. My input/output: [CODE]Input: http://localhost/key.txt Output: 687474703a2f2f6c6f63616c686f73742f6b65792e747874[/CODE] This random letters and numbers are our bytes. We need to convert these to look like this: [CODE]0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x6B, 0x65, 0x79, 0x2E, 0x74, 0x78, 0x74[/CODE] Simply split your output into values of two: [CODE]68 74 74 70...[/CODE] Add a "," after each (don't do this on the last byte): [CODE]68, 74, 74, 70,...[/CODE] And add "0x" in front of each: [CODE]0x68, 0x74, 0x74, 0x70,...[/CODE] Do this to all the bytes! Now we have a byte array to our key file on our webserver. Now lets place some text into this file, and attempt to display it in a MessageBox. I will put "test" into mine. [B]Double Click your Form[/B] Include these at the top of your code: [CODE]using System.Net; using System.Security.Cryptography;[/CODE] We now will create a byte array to our server. Place this code inside "Form1_Load": [CODE]byte[] myByteArray = { BYTE ARRAY REPLACES THIS TEXT };[/CODE] Now we can convert the bytes to text by using this function: [CODE]public string BytesToString(byte[] arr) { return Encoding.UTF8.GetString(arr); }[/CODE] Now we will show this in a message using a WebClient. Above the "private void Form1_Load(object sender, EventArgs e)" function, place this: [CODE]WebClient client = new WebClient();[/CODE] Now place this inside of "Form1_Load": [CODE]MessageBox.Show(client.DownloadString(BytesToString(myByteArray)));[/CODE] When you run this, a MessageBox should show and say "test". [/SPOILER] [SPOILER="String Encryption + Decryption Keys"] Now we need to use these two functions in order to Encrypt and Decrypt our strings: [CODE] string key = "L1$Ba8s!5)g$Sb41"; public string Encrypt(string data) { using (var des = new TripleDESCryptoServiceProvider { Mode = CipherMode.ECB, Key = Encoding.UTF8.GetBytes(key), Padding = PaddingMode.PKCS7 }) using (var desEncrypt = des.CreateEncryptor()) { var buffer = Encoding.UTF8.GetBytes(data); return Convert.ToBase64String(desEncrypt.TransformFinalBlock(buffer, 0, buffer.Length)); } } public string Decrypt(string data) { using (var des = new TripleDESCryptoServiceProvider { Mode = CipherMode.ECB, Key = Encoding.UTF8.GetBytes(key), Padding = PaddingMode.PKCS7 }) using (var desEncrypt = des.CreateDecryptor()) { var buffer = Convert.FromBase64String(data.Replace(" ", "+")); return Encoding.UTF8.GetString(desEncrypt.TransformFinalBlock(buffer, 0, buffer.Length)); } }[/CODE] As you may see, our key string is clearly visible, and anyone who gets this will be able to decrypt our top kek encrypted strings. We will Encrypt this using bytes, and store it on our webserver instead. Make sure to remove your key from your code, once you have chosen a key, make the: [CODE]string key = "L1$Ba8s!5)g$Sb41";[/CODE] be: [CODE]string key;[/CODE] Now, we [B]have to keep our key 16 characters long[/B], or it will not work. So make a 16 character key and throw it into the string to hex converter website again. [CODE]Input: L1$Ba8s!5)g$Sb41 Output: 4c312442613873213529672453623431[/CODE] We need to convert this to bytes again, but no "," or "0x" this time. My output looks like: [CODE]4C 31 24 42 61 38 73 21 35 29 67 24 53 62 34 31[/CODE] Now we replace "test" with the bytes above in our key.txt file. If we run our program now, we should get a MessageBox with the bytes you have entered. Now we want to convert this to be able to use it as our key. In Form1_Load, add this: [CODE] string ourKeyBytes = client.DownloadString(BytesToString(myByteArray)); byte[] bytes = ourKeyBytes.Split().Select(t => byte.Parse(t, System.Globalization.NumberStyles.AllowHexSpecifier)).ToArray(); key = BytesToString(bytes); [/CODE] Now our Encryption has a key, we can Encrypt a string. So lets create another file on our server and call it "test.txt". Under the code we have added in "Form1_Load", add this: [CODE]MessageBox.Show(Encrypt("STRING I WANNA ENCRYPT");[/CODE] Run the program and make note of the exact characters in the MessageBox... Put these into the string to HEX converter website again. I am Encrypting the string: [CODE]ProfoundModz[/CODE] When Encrypted, it is: [CODE]72JeeVa1RmLbwn0PJVU4RQ==[/CODE] Converting this to hex, it becomes:[CODE]37324a6565566131526d4c62776e30504a56553452513d3d[/CODE] Now we have to split this again, but only the spaces, no comma or "0x": [CODE]37 32 4A 65 65 56 61 31 52 6D 4C 62 77 6E 30 50 4A 56 55 34 52 51 3D 3D[/CODE] Now place this split hex into our "test.txt" file on our webserver, and attempt to retrieve and Decrypt it! Now we will use some of the same byte array as gaining the key in order to get this (same method at least), but instead of "[URL]http://localhost/key.txt[/URL]", we need "[URL]http://localhost/test.txt[/URL]" We only need to replace 3 bytes and add one. So our byte array for the key.txt link is: [CODE]0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x6B, 0x65, 0x79, 0x2E, 0x74, 0x78, 0x74[/CODE] You may notice the end being: [CODE]0x2E, 0x74, 0x78, 0x74[/CODE]. This is ".txt" in HEX. that must mean the last 7 bytes are "key.txt". From these, will update the first 3, and add one after. I will replace [CODE]0x6B, 0x65, 0x79[/CODE] to [CODE]0x74, 0x65, 0x73, 0x74[/CODE], as this is "test" in hex to bytes. Under the code already in "Form1_Load", remove the MessageBox.Show code, and add a new array: [CODE]byte[] myOtherByteArray = { BYTES HERE };[/CODE]. I will replace "BYTES HERE" with: [CODE]0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x74, 0x78, 0x74[/CODE] Now add this under our new byte array: [CODE]string myOtherMessageBytes = client.DownloadString(BytesToString(myOtherByteArray)); byte[] Otherbytes = myOtherMessageBytes.Split().Select(t => byte.Parse(t, System.Globalization.NumberStyles.AllowHexSpecifier)).ToArray();[/CODE] Now we can display the Decrypted text in a MessageBox like so: [CODE]MessageBox.Show(Decrypt(BytesToString(Otherbytes)));[/CODE] [/SPOILER] [SPOILER="Better Ways to do this"] I created a program so quickly Encrypt a string and byte it into the byte format (XX XX XX...) for me, and then I put this into a file using ":" between each encrypted string. Then I download it, and split it using ":" into an array, and then I can assign each string that I need to manually. If you'd like me to show you how to do this, PM me, and I'll share some sources. Also consider "downloading" parts of your code (encrypt it like above). I'll make a tutorial on this in the future. [/SPOILER] [SPOILER="End Tool Source"] [CODE] using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net; using System.Security.Cryptography; namespace String_Encryption_Tool { public partial class Form1 : Form { public Form1() { InitializeComponent(); } WebClient client = new WebClient(); public string BytesToString(byte[] arr) { return Encoding.UTF8.GetString(arr); } string key; public string Encrypt(string data) { using (var des = new TripleDESCryptoServiceProvider { Mode = CipherMode.ECB, Key = Encoding.UTF8.GetBytes(key), Padding = PaddingMode.PKCS7 }) using (var desEncrypt = des.CreateEncryptor()) { var buffer = Encoding.UTF8.GetBytes(data); return Convert.ToBase64String(desEncrypt.TransformFinalBlock(buffer, 0, buffer.Length)); } } public string Decrypt(string data) { using (var des = new TripleDESCryptoServiceProvider { Mode = CipherMode.ECB, Key = Encoding.UTF8.GetBytes(key), Padding = PaddingMode.PKCS7 }) using (var desEncrypt = des.CreateDecryptor()) { var buffer = Convert.FromBase64String(data.Replace(" ", "+")); return Encoding.UTF8.GetString(desEncrypt.TransformFinalBlock(buffer, 0, buffer.Length)); } } private void Form1_Load(object sender, EventArgs e) { byte[] myByteArray = { 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x6B, 0x65, 0x79, 0x2E, 0x74, 0x78, 0x74 }; //MessageBox.Show(client.DownloadString(BytesToString(myByteArray))); string myKeyBytes = client.DownloadString(BytesToString(myByteArray)); byte[] bytes = myKeyBytes.Split().Select(t => byte.Parse(t, System.Globalization.NumberStyles.AllowHexSpecifier)).ToArray(); key = BytesToString(bytes); byte[] myOtherByteArray = { 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0x2F, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x74, 0x78, 0x74 }; string myOtherMessageBytes = client.DownloadString(BytesToString(myOtherByteArray)); byte[] Otherbytes = myOtherMessageBytes.Split().Select(t => byte.Parse(t, System.Globalization.NumberStyles.AllowHexSpecifier)).ToArray(); MessageBox.Show(Decrypt(BytesToString(Otherbytes))); } } }[/CODE] [/SPOILER] ~ Harry [/QUOTE]
Verification
Post reply
Forums
Tech Boards
Computer Programming
Source Code & Tutorial
[C#] String Encryption using a WebServer
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top