Beispiel #1
0
 public Link(IDecrypt decrypt, IEncrypt encrypt, IPhysical physical, int maxFrameSize)
 {
     _decrypt = decrypt;
     _encrypt = encrypt;
     _physical = physical;
     _maxFrameSize = maxFrameSize;
 }
Beispiel #2
0
        private static string DecryptImplementation(string source, string key, IDecrypt decryptor)
        {
            Debug.Assert(source != null, "source != null");
            Debug.Assert(source.Length > 0, "source cannot be empty");
            Debug.Assert(decryptor != null, "decryptor != null");
            Debug.Assert(key != null, "key != null");
            Debug.Assert(key.Length >= decryptor.MinimumPasswordLength, "key too short");

            return decryptor.DecryptAES(source, key);
        }
Beispiel #3
0
        /// <summary>
        /// Provides simple AES decryption via a key for an encrypted Message.
        /// Must be encrypted with corresponding <see cref="Encrypt"/> method
        /// </summary>
        /// <param name="source">Encrypted string to be decrypted</param>
        /// <param name="key">Password to be used for decryption.  Default MinimumLength of 12 for default decryptor</param>
        /// <param name="decryptor">Optional <see cref="IDecrypt"/> to use.  Uses default implementation if none supplied.</param>
        /// <returns>Decrypted string.</returns>
        /// <exception cref="ValidationException">Occurs when <paramref name="source"/>is null or empty, when <paramref name="key"/> 
        /// is null or empty, when <paramref name="key"/> length is less than MinimumPasswordLength for <see cref="IEncrypt"/> to be used.
        /// </exception>
        public static string Decrypt(this string source, string key, IDecrypt decryptor = null)
        {
            var decryptorToUse = decryptor ?? new AESEncryption();

            Validate.Begin()
                .IsNotNull(source, "source")
                .IsNotEmpty(source, "source")
                .IsNotNull(key, "key")
                .IsNotEmpty(key, "key")
                .HasAtLeast(decryptorToUse.MinimumPasswordLength, key, "key")
                .CheckForExceptions();

            return DecryptImplementation(source, key, decryptorToUse);
        }
Beispiel #4
0
        private void SetDecrypter()
        {
            IDecrypt CezarDecodec   = new CezarDecodec();
            IDecrypt ReverseDecodec = new ReverseDecodec();
            IDecrypt FrameDecodec   = new FrameDecodec();
            IDecrypt SwapDecodec    = new SwapDecodec();
            IDecrypt PushDecodec    = new PushDecodec();

            bookDecrypter = new SwapDecodec();
            bookDecrypter.SetNext(CezarDecodec);
            CezarDecodec.SetNext(ReverseDecodec);
            ReverseDecodec.SetNext(FrameDecodec);

            CezarDecodec   = new CezarDecodec();
            ReverseDecodec = new ReverseDecodec();
            FrameDecodec   = new FrameDecodec();
            SwapDecodec    = new SwapDecodec();
            PushDecodec    = new PushDecodec();

            photoDecrypter = new ReverseDecodec();
            photoDecrypter.SetNext(PushDecodec);
            PushDecodec.SetNext(FrameDecodec);
            FrameDecodec.SetNext(CezarDecodec);

            CezarDecodec   = new CezarDecodec();
            ReverseDecodec = new ReverseDecodec();
            FrameDecodec   = new FrameDecodec();
            SwapDecodec    = new SwapDecodec();
            PushDecodec    = new PushDecodec();

            tripDecrypter = new PushDecodec();
            tripDecrypter.SetNext(SwapDecodec);
            SwapDecodec.SetNext(FrameDecodec);
            PushDecodec = new PushDecodec();
            FrameDecodec.SetNext(PushDecodec);
        }
Beispiel #5
0
 public Encryption(IEncrypt encrypt, IDecrypt decrypt)
 {
     _encrypt = encrypt;
     _decrypt = decrypt;
 }
 public void SetNext(IDecrypt decrypt)
 {
     this.next = decrypt;
 }
 public ZipContentsController(IDecrypt decryptor, IPersist persistor)
 {
     _decryptor = decryptor;
     _persistor = persistor;
 }
Beispiel #8
0
 public TodayWriter(IEncrypt encryptor, IDecrypt decryptor)
 {
     this._encryptor = encryptor;
     this._decryptor = decryptor;
 }
 public EncryptDecryptShowInConsole(IEncrypt encrypt, IDecrypt decrypt)
 {
     _encrypt = encrypt;
     _decrypt = decrypt;
 }
Beispiel #10
0
 public MenuLib(ILogger logger)
 {
     _logger  = logger;
     _encrypt = new Encrypt(_logger);
     _decrypt = new Decrypt(_logger);
 }
        /// <summary>
        /// 翻译API初始化
        /// </summary>
        /// <param name="param1">参数一 汉化补丁路径</param>
        /// <param name="param2">参数二 不使用</param>
        public void TranslatorInit(string patchPath, string mode)
        {
            initSettings(mode);
            bool     enc = false;
            IDecrypt decrypt = null;
            var      patch = new StreamReader(patchPath);
            string   temp = "";
            bool     jp = true, first = true;

            void add()
            {
                if (!first)
                {
                    if (jp)
                    {
                        jp_text.Add(temp);
                    }
                    else
                    {
                        cn_text.Add(temp);
                    }
                }
                else
                {
                    first = false;
                }
                temp = "";
            }

            string line;

            while ((line = patch.ReadLine()) != null)
            {
                if (line.StartsWith("#!"))
                {
                    Regex r = new Regex(@"#!useEnc=(.*),enc=(.*)", RegexOptions.IgnoreCase);
                    Match m = r.Match(line);
                    if (m.Success)
                    {
                        enc             = m.Groups[1].Value == "True";
                        PatchPermission = enc ? 0 : 1;
                        switch (m.Groups[2].Value)
                        {
                        case "xor":
                            decrypt = new XorDecrypt();
                            break;

                        case "aes":
                            decrypt = new AesDecrypt();
                            break;
                        }
                    }
                    continue;
                }
                if (enc)
                {
                    line = decrypt.DecryptString(line);
                }
                if (line == "\n" || line == "\r\n" || line.StartsWith("#"))
                {
                    //pass
                }
                else if (line.StartsWith("<j>"))
                {
                    add();
                    jp = true;
                }
                else if (line.StartsWith("<c>"))
                {
                    add();
                    jp = false;
                }
                else
                {
                    temp += line;
                }
            }
            add();
            if (jp_text.Count != cn_text.Count)
            {
                throw new Exception(String.Format("原文与译文行数不一致,原文{0},译文{1},请检查补丁",
                                                  jp_text.Count, cn_text.Count));
            }
        }