-
-
[原创]第十题 初入好望角(C#简单)
-
发表于: 2019-3-13 13:58 2824
-
程序逻辑很简单,输入验证码,适用密码加密后用base64编码再与4RTlF9Ca2+oqExJwx68FiA==
比较,如果相同,就是正确的flag。
我的电脑上没有Visual Studio,于是在这个网站在线测试了一下。本来想要把反编译过的代码,自己写解密函数的,但是结果总是不对。后来发现微软官方有个代码,抱着试试看的态度抄过来添加参数解密了一下,居然成功了!flag是Kanxue2019Q1CTF
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace RijndaelManaged_Example { public class RijndaelExample { public static void Main() { try { using (Rijndael myRijndael = Rijndael.Create()) { / / Encrypt the string to an array of bytes. / / byte[] encrypted = EncryptStringToBytes(original, myRijndael.Key, myRijndael.IV); byte[] encrypted = Convert.FromBase64String( "4RTlF9Ca2+oqExJwx68FiA==" ); myRijndael.Key = new PasswordDeriveBytes( "Kanxue2019" , null).GetBytes( 32 ); myRijndael.IV = Encoding.UTF8.GetBytes( "Kanxue2019CTF-Q1" ); string roundtrip = DecryptStringFromBytes(encrypted, myRijndael.Key, myRijndael.IV); Console.WriteLine( "Flags: {0}" , roundtrip); } } catch (Exception e) { Console.WriteLine( "Error: {0}" , e.Message); } } static string DecryptStringFromBytes(byte[] cipherText, byte[] Key, byte[] IV) { / / Check arguments. if (cipherText = = null || cipherText.Length < = 0 ) throw new ArgumentNullException( "cipherText" ); if (Key = = null || Key.Length < = 0 ) throw new ArgumentNullException( "Key" ); if (IV = = null || IV.Length < = 0 ) throw new ArgumentNullException( "IV" ); / / Declare the string used to hold / / the decrypted text. string plaintext = null; / / Create an Rijndael object / / with the specified key and IV. using (Rijndael rijAlg = Rijndael.Create()) { rijAlg.Key = Key; rijAlg.IV = IV; / / Create a decryptor to perform the stream transform. ICryptoTransform decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV); / / Create the streams used for decryption. using (MemoryStream msDecrypt = new MemoryStream(cipherText)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { / / Read the decrypted bytes from the decrypting stream / / and place them in a string. plaintext = srDecrypt.ReadToEnd(); } } } } return plaintext; } } } |
赞赏
他的文章
看原图
赞赏
雪币:
留言: