예제 #1
0
        private void WrapTest(
            int id,
            byte[]  kek,
            byte[]  iv,
            byte[]  input,
            byte[]  output)
        {
            IWrapper wrapper = new DesEdeWrapEngine();

            wrapper.Init(true, new ParametersWithIV(new DesEdeParameters(kek), iv));

            try
            {
                byte[] cText = wrapper.Wrap(input, 0, input.Length);
                if (!AreEqual(cText, output))
                {
                    Fail(": failed wrap test " + id + " expected " + Hex.ToHexString(output)
                         + " got " + Hex.ToHexString(cText));
                }
            }
            catch (Exception e)
            {
                Fail("failed wrap test exception: " + e.ToString(), e);
            }

            wrapper.Init(false, new DesEdeParameters(kek));

            try
            {
                byte[] pText = wrapper.Unwrap(output, 0, output.Length);
                if (!AreEqual(pText, input))
                {
                    Fail("failed unwrap test " + id + " expected " + Hex.ToHexString(input)
                         + " got " + Hex.ToHexString(pText));
                }
            }
            catch (Exception e)
            {
                Fail("failed unwrap test exception: " + e.ToString(), e);
            }
        }
예제 #2
0
        public static IWrapper GetWrapper(string algorithm)
        {
            string text  = Platform.ToUpperInvariant(algorithm);
            string text2 = (string)WrapperUtilities.algorithms[text];

            if (text2 == null)
            {
                text2 = text;
            }
            try
            {
                switch ((WrapperUtilities.WrapAlgorithm)Enums.GetEnumValue(typeof(WrapperUtilities.WrapAlgorithm), text2))
                {
                case WrapperUtilities.WrapAlgorithm.AESWRAP:
                {
                    IWrapper result = new AesWrapEngine();
                    return(result);
                }

                case WrapperUtilities.WrapAlgorithm.CAMELLIAWRAP:
                {
                    IWrapper result = new CamelliaWrapEngine();
                    return(result);
                }

                case WrapperUtilities.WrapAlgorithm.DESEDEWRAP:
                {
                    IWrapper result = new DesEdeWrapEngine();
                    return(result);
                }

                case WrapperUtilities.WrapAlgorithm.RC2WRAP:
                {
                    IWrapper result = new RC2WrapEngine();
                    return(result);
                }

                case WrapperUtilities.WrapAlgorithm.SEEDWRAP:
                {
                    IWrapper result = new SeedWrapEngine();
                    return(result);
                }

                case WrapperUtilities.WrapAlgorithm.DESEDERFC3211WRAP:
                {
                    IWrapper result = new Rfc3211WrapEngine(new DesEdeEngine());
                    return(result);
                }

                case WrapperUtilities.WrapAlgorithm.AESRFC3211WRAP:
                {
                    IWrapper result = new Rfc3211WrapEngine(new AesFastEngine());
                    return(result);
                }

                case WrapperUtilities.WrapAlgorithm.CAMELLIARFC3211WRAP:
                {
                    IWrapper result = new Rfc3211WrapEngine(new CamelliaEngine());
                    return(result);
                }
                }
            }
            catch (ArgumentException)
            {
            }
            IBufferedCipher cipher = CipherUtilities.GetCipher(algorithm);

            if (cipher != null)
            {
                return(new WrapperUtilities.BufferedCipherWrapper(cipher));
            }
            throw new SecurityUtilityException("Wrapper " + algorithm + " not recognised.");
        }