Esempio n. 1
0
        public void AESinECB_Test()  //ECB = Electronic Codebook
        {
            //https://cryptopals.com/sets/1/challenges/7
            string str   = Util.GetFile(7);
            string Hex   = MyConvert.Base64ToHex(str);
            var    bytes = MyConvert.HexToByteArray(Hex);

            string key      = "YELLOW SUBMARINE";
            string HexKey   = MyConvert.HexEncodePlainText(key);
            var    Keybytes = MyConvert.HexToByteArray(HexKey);

            var result    = MyCrypto.AES_ECB_Decrypt(bytes, Keybytes);
            var HexResult = MyConvert.BytesToHex(result);
            var Plain     = MyConvert.HexToAscii(HexResult);

            Assert.IsTrue("I'm back and I'm ringin' " == Plain.Substring(0, 25));
        }
Esempio n. 2
0
        public void AESinECB_Encrypt_Decrypt_Test()  //ECB = Electronic Codebook
        {
            string OriginalMessage = "Now is the time for all good men to come to the aid of their country";
            var    bytes           = MyConvert.TextToByteArray(OriginalMessage);
            var    PaddedBytes     = Pad.AddPkcs7(bytes, 128); //Pad the message to 128 bytes

            //The Key (16 bytes)
            string key      = "YELLOW SUBMARINE";
            string HexKey   = MyConvert.HexEncodePlainText(key);
            var    Keybytes = MyConvert.HexToByteArray(HexKey);

            //Encrypt
            var CiperBytes = MyCrypto.AES_ECB_Encrypt(PaddedBytes, Keybytes);

            //Decrypt
            var PlainBytes    = MyCrypto.AES_ECB_Decrypt(CiperBytes, Keybytes);
            var UnPaddedBytes = Pad.RemovePkcs7(PlainBytes); //Unpad the message
            var hexPlain      = MyConvert.BytesToHex(UnPaddedBytes);
            var PlainText     = MyConvert.HexToAscii(hexPlain);

            Assert.IsTrue(OriginalMessage == PlainText);
        }