Ejemplo n.º 1
0
        public static GPKeySet Diversify(GPKeySet keys, byte[] diversification_data, Diversification mode, int scp)
        {
            try
            {
                GPKeySet result = new GPKeySet();
                //Cipher cipher = Cipher.getInstance("DESede/ECB/NoPadding");
                foreach (KeySessionType v in KeyTypeList.Values)
                {
                    if (v == KeySessionType.RMAC)
                    {
                        continue;
                    }
                    byte[] kv = null;
                    // shift around and fill initialize update data as required.
                    if (mode == Diversification.VISA2)
                    {
                        kv = FillVisa(diversification_data, v);
                    }
                    else if (mode == Diversification.EMV)
                    {
                        kv = FillEmv(diversification_data, v);
                    }

                    // Encrypt with current master key
                    //cipher.init(Cipher.ENCRYPT_MODE, keys.getKey(v).getKey(Type.DES3));
                    //byte[] keybytes = cipher.doFinal(kv);
                    byte[] keybytes = GPCrypto.DoEncrypt_DES3_ECB(keys.GetKey(v).GetKey(KeyType.DES3).GetEncoded(), kv);

                    // Replace the key, possibly changing type. G&D SCE 6.0 uses EMV 3DES and resulting keys
                    // must be interpreted as AES-128
                    GPKey nk = new GPKey(keybytes, scp == 3 ? KeyType.AES : KeyType.DES3);
                    result.SetKey(v, nk);
                }
                return(result);
            }
            //catch (BadPaddingException e)
            //{
            //    throw new Exception("Diversification failed.", e);
            //}
            //catch (InvalidKeyException e)
            //{
            //    throw new Exception("Diversification failed.", e);
            //}
            //catch (IllegalBlockSizeException e)
            //{
            //    throw new Exception("Diversification failed.", e);
            //}
            //catch (NoSuchAlgorithmException e)
            //{
            //    throw new Exception("Diversification failed.", e);
            //}
            //catch (NoSuchPaddingException e)
            //{
            //    throw new Exception("Diversification failed.", e);
            //}
            catch (Exception e)
            {
                throw new Exception("Diversification failed.", e);
            }
        }
Ejemplo n.º 2
0
        public static GPPlaintextKeys FromMasterKey(GPKey master, Diversification div)
        {
            GPKeySet        ks = new GPKeySet(master);
            GPPlaintextKeys p  = new GPPlaintextKeys(ks, div)
            {
                master = master
            };

            return(p);
        }
Ejemplo n.º 3
0
 private void btn_start_Click(object sender, RoutedEventArgs e)
 {
     #region Confirm the format
     if (tb_inputFilePath.Text == String.Empty ||
         tb_outputPath.Text == String.Empty ||
         tb_lbound.Text == String.Empty ||
         tb_ubound.Text == String.Empty ||
         tb_a1.Text == String.Empty ||
         tb_a2.Text == String.Empty ||
         tb_a3.Text == String.Empty)
     {
         System.Windows.MessageBox.Show("Please complete input!");
         return;
     }
     try
     {
         Globals.LBound = Convert.ToInt32(tb_lbound.Text);
         Globals.UBound = Convert.ToInt32(tb_ubound.Text);
         Globals.A1     = Convert.ToDouble(tb_a1.Text);
         Globals.A2     = Convert.ToDouble(tb_a2.Text);
     }
     catch (Exception)
     {
         System.Windows.MessageBox.Show("Input string was not in a correct format.");
         return;
     }
     if (Globals.LBound >= Globals.UBound)
     {
         System.Windows.MessageBox.Show("UBound is smaller than LBound!");
         return;
     }
     if ((Globals.A1 > 1 || Globals.A1 < 0) ||
         (Globals.A2 > 1 || Globals.A2 < 0))
     {
         System.Windows.MessageBox.Show("The weight a1,a2,a3 ∈ (0,1]");
         return;
     }
     #endregion
     if (rb_hierarchical.IsChecked.Value)
     {
         initMethod = Initialization.HIERARCHICHAL;
     }
     else if (rb_RHier.IsChecked.Value)
     {
         initMethod = Initialization.RHIE;
     }
     else
     {
         initMethod = Initialization.NORMAL;
     }
     if (rb_minMax.IsChecked.Value)
     {
         normMethod = Normalization.MIN_MAX;
     }
     else
     {
         normMethod = Normalization.NONE;
     }
     if (rb_balance.IsChecked.Value)
     {
         diverMethod = Diversification.BALANCE;
     }
     else
     {
         diverMethod = Diversification.RERHIE;
     }
     fileL   = new FileStream(outputPath + "\\log_" + Globals.FileName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 4096, true);
     Util.sw = new StreamWriter(fileL);
     m_LB    = tb_lbound.Text;
     m_UB    = tb_ubound.Text;
     //将聚类任务交给bgw,锁定开始按钮
     //assign the task to bgw, disable the start button
     bgw.RunWorkerAsync();
     btn_start.IsEnabled = false;
 }
Ejemplo n.º 4
0
 private GPPlaintextKeys(GPKeySet keys, Diversification div)
 {
     staticKeys  = keys;
     diversifier = div;
     System.Diagnostics.Debug.WriteLine(String.Format("static keys: {0}", staticKeys.ToString()));
 }