Пример #1
0
        private static byte[] Mac_des_3des(GPKey key, byte[] text, int offset, int length, byte[] iv)
        {
            if (length == -1)
            {
                length = text.Length - offset;
            }

            try
            {
                //Cipher cipher1 = Cipher.getInstance(DES_CBC_CIPHER);
                //cipher1.init(Cipher.ENCRYPT_MODE, key.getKey(Type.DES), new IvParameterSpec(iv));
                //Cipher cipher2 = Cipher.getInstance(DES3_CBC_CIPHER);
                //cipher2.init(Cipher.ENCRYPT_MODE, key.getKey(Type.DES3), new IvParameterSpec(iv));

                byte[] result = Arrays.Clone(iv);
                byte[] temp;
                if (length > 8)
                {
                    temp = GPCrypto.DoEncrypt_DES_CBC(key.GetKey(KeyType.DES).GetEncoded(), text, offset, length - 8, iv);
                    Array.Copy(temp, temp.Length - 8, result, 0, 8);
                }
                temp = GPCrypto.DoEncrypt_DES3_CBC(key.GetKey(KeyType.DES3).GetEncoded(), text, (offset + length) - 8, 8, result);
                Array.Copy(temp, temp.Length - 8, result, 0, 8);
                return(result);
            }
            catch (Exception e)
            {
                //e.printStackTrace();
                throw new Exception("MAC computation failed.", e);
            }
        }
Пример #2
0
 private static byte[] Scp03_key_check_value(GPKey key)
 {
     try
     {
         byte[] cv = GPCrypto.DoEncrypt_AES_CBC(key.GetKey().GetEncoded(), GPCrypto.one_bytes_16);
         //Cipher c = Cipher.getInstance(AES_CBC_CIPHER);
         //c.init(Cipher.ENCRYPT_MODE, key.getKey(), iv_null_aes);
         //byte[] cv = c.doFinal(one_bytes_16);
         return(Arrays.CopyOfRange(cv, 0, 3));
     }
     catch (Exception e)
     {
         throw new Exception("Could not calculate key check value: ", e);
     }
 }
Пример #3
0
        //public static IvParameterSpec iv_null_des = new IvParameterSpec(null_bytes_8);
        //public static IvParameterSpec iv_null_aes = new IvParameterSpec(null_bytes_16);

        public static byte[] Kcv_3des(GPKey key)
        {
            try
            {
                byte[] check = DoEncrypt_DES3_ECB(key.GetKey().GetEncoded(), null_bytes_8);
                //Cipher cipher = Cipher.getInstance("DESede/ECB/NoPadding");
                //cipher.init(Cipher.ENCRYPT_MODE, key.getKey());
                //byte check[] = cipher.doFinal(GPCrypto.null_bytes_8);
                return(Arrays.CopyOf(check, 3));
            }
            catch (Exception e)
            {
                throw new Exception("Could not calculate KCV", e);
            }
        }
Пример #4
0
 private static byte[] Mac_3des(GPKey key, byte[] text, byte[] iv)
 {
     byte[] d = Pad80(text, 8);
     return(Mac_3des(key.GetKey(), d, 0, d.Length, iv));
 }