/// <summary>
 /// 构造函数
 /// </summary>
 public MACTripleDESEncrypt()
 {
     mact = new MACTripleDES();
 }
예제 #2
0
 public void ConstructorNameNullKeyNull()
 {
     algo = new MACTripleDES(null, null);
 }
예제 #3
0
 public HashAlgorithm CreateMACTripleDES() => MACTripleDES.Create();
예제 #4
0
 public void ConstructorNameKey()
 {
     byte[] key = CombineKeys(key1, key2, key3);
     algo = new MACTripleDES("TripleDES", key);
 }
예제 #5
0
 // LAMESPEC: [ExpectedException (typeof (ArgumentNullException))]
 public void ConstructorNameNullKey()
 {
     byte[] key = CombineKeys(key1, key2, key3);
     // funny null is a valid name!
     algo = new MACTripleDES(null, key);
 }
예제 #6
0
 public void InvalidAlgorithmName()
 {
     byte[] key = CombineKeys(key1, key2, key3);
     algo = new MACTripleDES("DES", key);
 }
예제 #7
0
 public void ConstructorEmpty()
 {
     algo = new MACTripleDES();
 }
예제 #8
0
        public static bool Test(Session session)
        {
            bool bRes = true;

            byte[] plaintext = new byte[16];
            for (int i = 0; i < plaintext.Length - 5; i++)
            {
                plaintext[i] = (byte)i;
            }
            for (int i = plaintext.Length - 5; i < plaintext.Length; i++)
            {
                plaintext[i] = (byte)0;
            }

            byte[] plaintext1 = new byte[plaintext.Length - 5];
            for (int i = 0; i < plaintext1.Length; i++)
            {
                plaintext1[i] = (byte)i;
            }

            SymmetricAlgorithm td = new TripleDESCryptoServiceProvider(session);

            td.Padding = PaddingMode.None;
            td.IV      = new byte[8];

            ICryptoTransform sse = td.CreateEncryptor();
            //MemoryStream ms = new MemoryStream(plaintext);
            ICryptoTransform ct = td.CreateEncryptor();

            //CryptoStream cs1 = new CryptoStream(ms, sse, CryptoStreamMode.Write);
            //cs1.Write(plaintext, 0, plaintext.Length);
            //cs1.FlushFinalBlock();
            //Log.Comment(ms.Position);
            //byte[] ciphertext = ms.ToArray();
            //cs1.Close();
            byte[] ciphertext = ct.TransformFinalBlock(plaintext, 0, plaintext.Length);
            ct.Dispose();

            Log.Comment("CipherText:");
            PrintByteArray(ciphertext);

            td.Padding = PaddingMode.Zeros;
            ICryptoTransform sse1 = td.CreateEncryptor();

            //MemoryStream ms1 = new MemoryStream();
            //CryptoStream cs2 = new CryptoStream(ms1, sse1, CryptoStreamMode.Write);
            //cs2.Write(plaintext1, 0, plaintext1.Length);
            cs2.FlushFinalBlock();
            Log.Comment(ms1.Position);
            byte[] ciphertext1 = ms1.ToArray();
            cs2.Close();

            Log.Comment("CipherText #2:");
            PrintByteArray(ciphertext1);

            if (!Compare(ciphertext, ciphertext1))
            {
                bRes = false;
                Log.Comment("WRONG: ciphertexts are different. Probably padding problems.");
            }


            MACTripleDES mtd = new MACTripleDES(td.Key);

            byte[] hash = mtd.ComputeHash(plaintext1);

            Log.Comment("Hash:");
            PrintByteArray(hash);

            byte[] subciphertext = new byte[8];
            Array.Copy(ciphertext, ciphertext.Length - 8, subciphertext, 0, 8);

            if (!Compare(subciphertext, hash))
            {
                Log.Comment("WRONG: MAC3DES result is different from the last block of ciphertext!");
                bRes = false;
            }

            return(bRes);
        }
예제 #9
0
 public void ConstructorNameKey()
 {
     byte[] key = CombineKeys(key1, key2, key3);
     algo = new MACTripleDES("TripleDES", key);
     AssertNotNull("MACTripleDES ('TripleDES',key)", algo);
 }
예제 #10
0
 public void ConstructorEmpty()
 {
     algo = new MACTripleDES();
     AssertNotNull("MACTripleDES ()", algo);
 }
예제 #11
0
파일: Encrypt.cs 프로젝트: d8q8/DoIt
 public MacTripleDesEncrypt()
 {
     _mact = new MACTripleDES();
 }
예제 #12
0
        /// <summary>ハッシュ(キー付き)サービスプロバイダの生成</summary>
        /// <param name="ekha">ハッシュ(キー付き)サービスプロバイダの列挙型</param>
        /// <param name="key">キー</param>
        /// <returns>ハッシュ(キー付き)サービスプロバイダ</returns>
        public static KeyedHashAlgorithm CreateKeyedHashAlgorithmSP(EnumKeyedHashAlgorithm ekha, byte[] key)
        {
            // ハッシュ(キー付き)サービスプロバイダ
            KeyedHashAlgorithm kha = null;

            // HMACSHA1.Create(); だと、全部、HMACSHA1になってしまう現象があったので、
            // 全部、= new HMACSHA1(key); のスタイルに変更した。

            if (ekha == EnumKeyedHashAlgorithm.Default)
            {
                // 既定の暗号化サービスプロバイダ
                kha = new HMACSHA1(key); // devps(1703)
            }

            else if (ekha == EnumKeyedHashAlgorithm.HMACSHA1)
            {
                // HMACSHA1サービスプロバイダ
                kha = new HMACSHA1(key); // devps(1703)
            }
            // -- ▼追加▼ --
            else if (ekha == EnumKeyedHashAlgorithm.HMACMD5)
            {
                // HMACMD5サービスプロバイダ
                kha = new HMACMD5(key);
            }
            else if (ekha == EnumKeyedHashAlgorithm.HMACRIPEMD160)
            {
#if NETSTD
                kha = null; // BouncyCastleを使用する。
#else
                // HMACRIPEMD160サービスプロバイダ
                kha = new HMACRIPEMD160(key);
#endif
            }
            else if (ekha == EnumKeyedHashAlgorithm.HMACSHA256)
            {
                // HMACSHA256サービスプロバイダ
                kha = new HMACSHA256(key);
            }
            else if (ekha == EnumKeyedHashAlgorithm.HMACSHA384)
            {
                // HMACSHA384サービスプロバイダ
                kha = new HMACSHA384(key);
            }
            else if (ekha == EnumKeyedHashAlgorithm.HMACSHA512)
            {
                // HMACSHA512サービスプロバイダ
                kha = new HMACSHA512(key);
            }
            // -- ▲追加▲ --
            else if (ekha == EnumKeyedHashAlgorithm.MACTripleDES)
            {
#if NETSTD
                kha = null; // BouncyCastleを使用する。
#else
                // MACTripleDESサービスプロバイダ
                kha = new MACTripleDES(key); // devps(1703)
#endif
            }
            else
            {
                throw new ArgumentException(
                          PublicExceptionMessage.ARGUMENT_INCORRECT, "EnumKeyedHashAlgorithm ekha");
            }

            return(kha);
        }