private void Button_Click(object sender, RoutedEventArgs e)
        {
            Stream source = null;

            if (FileSelectRadio.IsChecked.GetValueOrDefault())
            {
                source = new FileStream(inputFileName, FileMode.Open, FileAccess.Read);
            }
            else if (BitsSelectRadio.IsChecked.GetValueOrDefault())
            {
                source = new MemoryStream(BitsUtils.ToBinary(BitsTextBox.Text));
            }
            else
            {
                throw new Exception("Source not specified");
            }
            int mode = 0;

            if (DECCRadio.IsChecked.GetValueOrDefault())
            {
                mode = 2;
            }
            else if (SECCRadio.IsChecked.GetValueOrDefault())
            {
                mode = 1;
            }
            else
            {
                throw new Exception("Mode not specified");
            }

            if (FileOutputCheckBox.IsChecked.GetValueOrDefault())
            {
                SaveFileDialog dialog = new SaveFileDialog();
                if (dialog.ShowDialog() == true)
                {
                    using (var fs = new FileStream(dialog.FileName, FileMode.Create, FileAccess.Write))
                    {
                        ECC.Decode(mode, source, fs);
                    }
                }
            }
            else
            {
                OutputText.Document.Blocks.Clear();
                byte[] encoded = Telekom.ECC.Decode(mode, source);
                for (int i = 0; i < encoded.Length; i++)
                {
                    OutputText.AppendText(Convert.ToString(encoded[i], 2).PadLeft(8, '0'));
                }
            }
            source.Close();
        }
예제 #2
0
        public void TestSetup()
        {
            controller = new ECCController();
            var result = controller.Index() as ViewResult;

            ecc     = (ECC)result.ViewData.Model;
            context = new Mock <ControllerContext>();
            session = new Mock <HttpSessionStateBase>();
            context.Setup(m => m.HttpContext.Session).Returns(session.Object);
            controller.ControllerContext = context.Object;
            session.Setup(s => s["ECCModel"]).Returns(ecc);
        }
예제 #3
0
        /// <summary>
        /// 设置扩展配置
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Obj"></param>
        public static void SetExtendConfig <T>(T Obj)
        {
            ProteinConfig pconfig = ProteinConfig.GetInstance();
            ECC           ecc     = MachineExConfig.GetExtendConfig();

            foreach (ExConfig config in pconfig.ExConfigs)
            {
                if (config.Name == typeof(T).FullName)
                {
                    ecc.SaveExtendConfig <T>(config.GetType().Assembly.GetAssemblyPath() + config.ConfigXMLPath + "\\" + config.ConfigXML, Obj);
                }
            }
        }
예제 #4
0
        public void TestIndexPostValues()
        {
            ecc.BandAColor = "Yellow";
            ecc.BandBColor = "Violet";
            ecc.BandCColor = "Red";
            ecc.BandDColor = "Gold";
            var result = controller.Index(ecc) as ViewResult;

            ecc = (ECC)result.ViewData.Model;
            Assert.AreEqual(4700, ecc.OhmValue);
            Assert.AreEqual(4465, ecc.LowerBoundValue);
            Assert.AreEqual(4935, ecc.UpperBoundValue);
        }
예제 #5
0
        public byte[] DecryptAes256Cbc4Broadcast(byte[] data)
        {
            //blocksize = OpenSSL.get_cipher(ciphername).get_blocksize()
            const int blocksize = 16;

            //iv = data[:blocksize]
            //i = blocksize
            int pos = 0;
            var iv  = data.ReadBytes(ref pos, blocksize);

            //curve, pubkey_x, pubkey_y, i2 = ECC._decode_pubkey(data[i:])
            //i += i2
            UInt16 curve;

            byte[] pubkeyX;
            byte[] pubkeyY;
            ECC._decode_pubkey(data, out curve, out pubkeyX, out pubkeyY, ref pos);

            //ciphertext = data[i:len(data)-32]
            //i += len(ciphertext)
            var ciphertext = data.ReadBytes(ref pos, data.Length - pos - 32);

            //mac = data[i:]
            var mac = data.ReadBytes(ref pos, 32);

            //key = sha512(self.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
            byte[] key;
            using (var sha512 = new SHA512Managed())
                key = sha512.ComputeHash(new ECC(null, null, null, null, Sha512VersionStreamHashFirst32(), ECC.Secp256K1).raw_get_ecdh_key(pubkeyX, pubkeyY));

            //key_e, key_m = key[:32], key[32:]
// ReSharper disable InconsistentNaming
            var key_e = new byte[32];
            var key_m = new byte[32];

// ReSharper restore InconsistentNaming
            Buffer.BlockCopy(key, 0, key_e, 0, 32);
            Buffer.BlockCopy(key, 32, key_m, 0, 32);

            //if hmac_sha256(key_m, ciphertext) != mac:
            //	raise RuntimeError("Fail to verify data")
            if (!new HMACSHA256(key_m).ComputeHash(ciphertext).SequenceEqual(mac))
            {
                throw new Exception("Fail to verify data");
            }

            var ctx = new Cipher(key_e, iv, false);

            return(ctx.Ciphering(ciphertext));
        }
예제 #6
0
        /// <summary>
        /// 初始化扩展配置
        /// </summary>
        protected virtual void InisExConfig()
        {
            excc = new ECC();
            ProteinConfig pconfig = ProteinConfig.GetInstance();

            foreach (ExConfig config in pconfig.ExConfigs)
            {
                string xmlfilepath = this.GetType().Assembly.GetAssemblyPath()
                                     + config.ConfigXMLPath + "/" + config.ConfigXML;
                string dllfilepath = this.GetType().Assembly.GetAssemblyPath()
                                     + config.TypeFlagPath + "/" + config.TypeFlag;
                excc.AddExtendConfig(xmlfilepath, dllfilepath, config);
            }
        }
예제 #7
0
        private void preparePackage(UInt32 version, string applicationPath)
        {
            AES aes = new AES(encKey);
            ECC ecc = new ECC(ECC.KeySize.Key256, signingKey);

            /*
             * How to prepare a package
             * 1. Read the application image first
             * 2. Encrypt it
             * 3. Sign the encrypted image
             * 4. Create the metadata for the encrypted and signed application image
             * 5. Write the metadata and the encrypted image into a file. (The bootloader will be using this file)
             */

            /* Read the Application Image */
            byte[] applicationImage = getApplicationImage(applicationPath);

            /* Encrypt the Application Image */
            byte[] encryptedApplicationImage = aes.Encrypt(applicationImage);

            /* Sign the encrypted image */
            byte[] signature = ecc.Sign(encryptedApplicationImage);

            /* Create a metadata  */
            byte[] metaData = getMetaData(version, (UInt32)encryptedApplicationImage.Length, aes.IV, signature);

            /* Write Metadata and the encrypted image into the upgrade package */
            {
                string packagePath = applicationPath + ".package.bin";

                if (File.Exists(packagePath))
                {
                    File.Delete(packagePath);
                }

                using (FileStream fs = new FileStream(packagePath, FileMode.CreateNew))
                {
                    using (BinaryWriter bS = new BinaryWriter(fs))
                    {
                        bS.Write(metaData);
                        bS.Write(encryptedApplicationImage);
                        bS.Close();
                    }
                    fs.Close();
                }
            }
        }
예제 #8
0
        public ActionResult Index(ECC model)
        {
            var colorAList     = GetAllColors();
            var colorBList     = GetAllColors();
            var multiplierList = GetMultipliersColors();
            var toleranceList  = GetToleranceColors();

            model.BandAColors = GetSelectListItems(colorAList);
            model.BandBColors = GetSelectListItems(colorBList);
            model.BandCColors = GetSelectListItems(multiplierList);
            model.BandDColors = GetSelectListItems(toleranceList);


            if (ModelState.IsValid)
            {
                Session["ECCModel"] = model;
                Calculate();
            }

            return(View("Index", model));
        }
예제 #9
0
        ///// <summary>
        ///// 获取扩展配置对象
        ///// </summary>
        ///// <typeparam name="T"></typeparam>
        //public T ExtendConfig<T>()
        //{
        //    ECC ecc = MachineExConfig.GetExtendConfig();
        //    return (T)ecc.GetExtendConfig<T>();
        //}

        /// <summary>
        /// 添加扩展配置对象
        /// </summary>
        /// <param name="NewObject"></param>
        public void AddExtendConfig(object NewObject)
        {
            ECC ecc = MachineExConfig.GetExtendConfig();

            ecc.AddExtendConfig(NewObject);
        }
예제 #10
0
        /// <summary>
        /// 获取扩展配置对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T GetExtendConfig <T>()
        {
            ECC ecc = MachineExConfig.GetExtendConfig();

            return((T)ecc.GetExtendConfig <T>());
        }
예제 #11
0
 public void TestSetup()
 {
     model = new ECC();
 }