Exemplo n.º 1
0
 async void DropFile(object o, DragEventArgs e, EncryptMode em)
 {
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
         foreach (string file in files)
         {
             if (em == EncryptMode.Encrypt)
             {
                 if (!(await FileCrypt(file)))
                 {
                     MessageBox.Show($"Error while encrypting {file}. Check the Error log for more information.");
                 }
             }
             else if (em == EncryptMode.Decrypt)
             {
                 if (!(await FileDecrypt(file)))
                 {
                     MessageBox.Show($"Error while decrypting {file}. Check the Error log for more information.");
                 }
             }
             else if (em == EncryptMode.Key)
             {
                 if (!(LoadKey(file)))
                 {
                     MessageBox.Show($"Error while loading {file}. Check the Error log for more information.");
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public void Encrypt(IByteBufferAllocator allocator, EncryptMode mode, Stream src, Stream dst, bool reliable)
        {
            using (var data = new BufferWrapper(allocator.Buffer().WithOrder(ByteOrder.LittleEndian)))
                using (var encryptor = GetAlgorithm(mode).CreateEncryptor())
                    using (var cs = new CryptoStream(new NonClosingStream(dst), encryptor, CryptoStreamMode.Write))
                        using (var w = cs.ToBinaryWriter(false))
                        {
                            var blockSize = AES.BlockSize / 8;
                            var padding   = blockSize - (src.Length + 1 + 4) % blockSize;
                            if (reliable)
                            {
                                padding = blockSize - (src.Length + 1 + 4 + 2) % blockSize;
                            }

                            if (reliable)
                            {
                                var counter = (ushort)(Interlocked.Increment(ref _encryptCounter) - 1);
                                data.Buffer.WriteShort(counter);
                            }

                            using (var dataStream = new WriteOnlyByteBufferStream(data.Buffer, false))
                                src.CopyTo(dataStream);

                            w.Write((byte)padding);
                            using (var dataStream = new ReadOnlyByteBufferStream(data.Buffer, false))
                            {
                                w.Write(Hash.GetUInt32 <CRC32>(dataStream));
                                dataStream.Position = 0;
                                dataStream.CopyTo(cs);
                            }
                            w.Fill((int)padding);
                        }
        }
Exemplo n.º 3
0
        private void Init()
        {
            _asset       = new AssetInfo(Application.dataPath, "Assets", true);
            _validAssets = new List <AssetInfo>();
            AssetBundleTool.ReadAssetsInChildren(_asset, _validAssets);

            _assetBundle = new AssetBundleInfo();
            AssetBundleTool.ReadAssetBundleConfig(_assetBundle, _validAssets);

            _buildPath = AssetBundleTool.EditorConfigInfo.BuildPath;
            List <int> buildTargets = AssetBundleTool.EditorConfigInfo.BuildTargets;

            string[] buildTargtNames = Enum.GetNames(typeof(BuildTarget));
            for (int i = 0; i < buildTargtNames.Length; i++)
            {
                BuildTarget target = (BuildTarget)Enum.Parse(typeof(BuildTarget), (buildTargtNames[i]));
                _buildTargets.Add(buildTargtNames[i], buildTargets.Contains((int)target));
            }
            //z = (BuildTarget) AssetBundleTool.EditorConfigInfo.BuildTarget;
            _zipMode      = (ZipMode)AssetBundleTool.EditorConfigInfo.ZipMode;
            _encryptMode  = (EncryptMode)AssetBundleTool.EditorConfigInfo.EncryptMode;
            _assetVersion = AssetBundleTool.EditorConfigInfo.AssetVersion;

            Resources.UnloadUnusedAssets();
        }
        /***
         * This function decrypts the encrypted text to plain text using the key
         * provided. You'll have to use the same key which you used during
         * encryption
         *
         * @param _encryptedText
         *            Encrypted/Cipher text to be decrypted
         * @param _key
         *            Encryption key which you used during encryption
         */

        private string encryptDecrypt(string _inputText, string _encryptionKey, EncryptMode _mode, string _initVector)
        {
            SymmetricKeyAlgorithmProvider aesCbcPkcs7 = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);

            // Creata a 16 byte initialization vector
            IBuffer iv = CryptographicBuffer.ConvertStringToBinary(_initVector, BinaryStringEncoding.Utf8);

            // Create an AES 128-bit (16 byte) key
            IBuffer          keyMaterial = CryptographicBuffer.ConvertStringToBinary(_encryptionKey, BinaryStringEncoding.Utf8);
            CryptographicKey key         = aesCbcPkcs7.CreateSymmetricKey(keyMaterial);

            if (_mode.Equals(EncryptMode.ENCRYPT))
            {
                // Encrypt the data
                IBuffer plainText      = CryptographicBuffer.ConvertStringToBinary(_inputText, BinaryStringEncoding.Utf8);
                IBuffer cipherText     = CryptographicEngine.Encrypt(key, plainText, iv);
                string  strEncrypted64 = CryptographicBuffer.EncodeToBase64String(cipherText);
                return(strEncrypted64);
            }
            else
            {
                // Decrypt the data
                IBuffer cipherText    = CryptographicBuffer.DecodeFromBase64String(_inputText);
                IBuffer decryptedText = CryptographicEngine.Decrypt(key, cipherText, iv);
                return(CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, decryptedText));
            }
        }
Exemplo n.º 5
0
            private String encryptDecrypt(string _inputText, string _encryptionKey, EncryptMode _mode, string _initVector)
            {
                string _out = "";

                //get hashed pin code to bytes array
                _pwd = Encoding.UTF8.GetBytes(_encryptionKey);
                //get IV to byte array
                _ivBytes = Encoding.UTF8.GetBytes(_initVector);

                //check that the IV and hashed key are the correct size in bytes
                int len = _pwd.Length;

                if (len > _key.Length)
                {
                    len = _key.Length;
                }
                int ivLenth = _ivBytes.Length;

                if (ivLenth > _iv.Length)
                {
                    ivLenth = _iv.Length;
                }

                //copy hashed pincode and IV bytes to AES key and IV
                Array.Copy(_pwd, _key, len);
                Array.Copy(_ivBytes, _iv, ivLenth);
                _rcipher.Key = _key;
                _rcipher.IV  = _iv;

                //encrypt mode
                if (_mode.Equals(EncryptMode.ENCRYPT))
                {
                    //encrypt the password
                    byte[] plainText = _rcipher.CreateEncryptor().TransformFinalBlock(_enc.GetBytes(_inputText),
                                                                                      0, _inputText.Length);
                    //combine the ciphertext and the IV so we can use it later
                    byte[] combined = new byte[_iv.Length + plainText.Length];
                    System.Buffer.BlockCopy(_iv, 0, combined, 0, _iv.Length);
                    System.Buffer.BlockCopy(plainText, 0, combined, _iv.Length, plainText.Length);
                    //convert ciphertext bytes to hex
                    _out = Convert.ToBase64String(combined);
                }

                //decrypt mode
                if (_mode.Equals(EncryptMode.DECRYPT))
                {
                    //decrypt the ciphertext back to plaintext using the same IV
                    byte[] plainText = _rcipher.CreateDecryptor().TransformFinalBlock(Convert.FromBase64String(_inputText),
                                                                                      0, Convert.FromBase64String(_inputText).Length);
                    //convert plaintext bytes back to hex
                    String outputToString = _enc.GetString(plainText);
                    //remove IV from plaintext
                    String trimmed = outputToString.Remove(0, _iv.Length - 1);
                    _out = trimmed;
                }
                _rcipher.Dispose();
                return(_out);
            }
        public override void Initialize(object initializer)
        {
            SoapSecurityExtensionAttribute attribute = (SoapSecurityExtensionAttribute)initializer;

            decryptMode = attribute.Decrypt;
            encryptMode = attribute.Encrypt;
            target      = attribute.Target;
            return;
        }
        public override void Initialize(object initializer)
        {
            SoapSecurityExtensionAttribute attribute = (SoapSecurityExtensionAttribute)initializer;

            decryptMode = attribute.Decrypt;
            encryptMode = attribute.Encrypt;
            target = attribute.Target;
            return;
        }
Exemplo n.º 8
0
        private SymmetricAlgorithm GetAlgorithm(EncryptMode mode)
        {
            switch (mode)
            {
            case EncryptMode.Secure:
                return(AES);

            default:
                throw new ArgumentException("Invalid mode", nameof(mode));
            }
        }
Exemplo n.º 9
0
        private void SettingGUI()
        {
            if (_showSetting)
            {
                GUI.BeginGroup(new Rect((int)position.width / 2 - 125, (int)position.height / 2 - 65, 250, 130), "", _flownode0on);

                GUI.Label(new Rect(5, 5, 80, 20), "Build Target: ");
                BuildTarget buildTarget = (BuildTarget)EditorGUI.EnumPopup(new Rect(90, 5, 155, 20), _buildTarget, _preDropDown);
                if (buildTarget != _buildTarget)
                {
                    _buildTarget = buildTarget;
                    AssetBundleTool.EditorConfigInfo.BuildTarget = (int)_buildTarget;
                    AssetBundleTool.SaveEditorConfigInfo();
                }

                GUI.Label(new Rect(5, 30, 80, 20), "Zip Mode: ");
                ZipMode zipMode = (ZipMode)EditorGUI.EnumPopup(new Rect(90, 30, 155, 20), _zipMode, _preDropDown);
                if (zipMode != _zipMode)
                {
                    _zipMode = zipMode;
                    AssetBundleTool.EditorConfigInfo.ZipMode = (int)_zipMode;
                    AssetBundleTool.SaveEditorConfigInfo();
                }

                GUI.Label(new Rect(5, 55, 80, 20), "Encrypt: ");
                EncryptMode encryptMode = (EncryptMode)EditorGUI.EnumPopup(new Rect(90, 55, 155, 20), _encryptMode, _preDropDown);
                if (encryptMode != _encryptMode)
                {
                    _encryptMode = encryptMode;
                    AssetBundleTool.EditorConfigInfo.EncryptMode = (int)encryptMode;
                    AssetBundleTool.SaveEditorConfigInfo();
                }

                GUI.Label(new Rect(5, 80, 150, 20), "Asset Version: " + _assetVersion);
                if (GUI.Button(new Rect(150, 80, 95, 20), "Reset", _preButton))
                {
                    _assetVersion = 1;
                    AssetBundleTool.EditorConfigInfo.AssetVersion = _assetVersion;
                    AssetBundleTool.SaveEditorConfigInfo();
                }

                if (GUI.Button(new Rect(100, 105, 50, 20), "Sure", _preButton))
                {
                    _showSetting = false;
                }

                GUI.EndGroup();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 解密字符串(失败返回空)
        /// </summary>
        /// <param name="DecryptString">待解密字符串</param>
        /// <param name="Mode">加密模式</param>
        /// <returns></returns>
        public static string Decode(string DecryptString, EncryptMode Mode)
        {
            string ReturnString = "";

            if (Mode == EncryptMode.Cipher)
            {
                return(ReturnString);
            }

            List <EncryptInfo> EncryptList = EncryptConfigs.GetConfig().EncryptInfo;

            try {
                foreach (EncryptInfo el in EncryptList)
                {
                    EncryptMode TempMode = Utils.GetEnum <EncryptMode>(el.EncryptName.Trim(), EncryptMode.Default);

                    if (Mode.Equals(TempMode))
                    {
                        ReturnString = DecryptString;

                        //反向解密
                        for (int i = el.EncryptType.Count - 1; i >= 0; i--)
                        {
                            EncryptType ei = el.EncryptType[i];

                            switch (ei.Type)
                            {
                            case EncryptEnum.AES:
                                ReturnString = AES.Decode(ReturnString, ei.Key);
                                break;

                            case EncryptEnum.DES:
                                ReturnString = DES.Decode(ReturnString, ei.Key);
                                break;

                            default:
                                break;
                            }
                        }

                        break;
                    }
                }
            }
            catch { ReturnString = ""; }

            return(ReturnString);
        }
Exemplo n.º 11
0
        private void Init()
        {
            _asset       = new AssetInfo(Application.dataPath, "Assets", true);
            _validAssets = new List <AssetInfo>();
            AssetBundleTool.ReadAssetsInChildren(_asset, _validAssets);

            _assetBundle = new AssetBundleInfo();
            AssetBundleTool.ReadAssetBundleConfig(_assetBundle, _validAssets);

            _buildPath    = AssetBundleTool.EditorConfigInfo.BuildPath;
            _buildTarget  = (BuildTarget)AssetBundleTool.EditorConfigInfo.BuildTarget;
            _zipMode      = (ZipMode)AssetBundleTool.EditorConfigInfo.ZipMode;
            _encryptMode  = (EncryptMode)AssetBundleTool.EditorConfigInfo.EncryptMode;
            _assetVersion = AssetBundleTool.EditorConfigInfo.AssetVersion;

            Resources.UnloadUnusedAssets();
        }
Exemplo n.º 12
0
        private void InitSetting(bool create)
        {
            SetSetting("FileVersion", "1.0");
            SetSetting("EncryptMode", EncryptMode.ToString());

            string checkCodeOld = GetSetting("CheckCode");

            if (create || string.IsNullOrEmpty(checkCodeOld))
            {
                var checkCode = GetRandamKey();

                string hash = ConvertCheckCodeToHash(checkCode);

                SetSetting("CheckCode", checkCode);
                SetSetting("CheckHash", hash);
            }
        }
Exemplo n.º 13
0
        public void Decrypt(IByteBufferAllocator allocator, EncryptMode mode, Stream src, Stream dst, bool reliable)
        {
            if (RC4 == null || AES == null)
            {
                return;
            }
            //throw new ObjectDisposedException(GetType().FullName);

            using (var data = new BufferWrapper(allocator.Buffer().WithOrder(ByteOrder.LittleEndian)))
                using (var decryptor = GetAlgorithm(mode).CreateDecryptor())
                    using (var cs = new CryptoStream(src, decryptor, CryptoStreamMode.Read))
                    {
                        var padding  = cs.ReadByte();
                        var checksum = cs.ReadByte() | (cs.ReadByte() << 8) | (cs.ReadByte() << 16) | (cs.ReadByte() << 24);

                        using (var dataStream = new WriteOnlyByteBufferStream(data.Buffer, false))
                        {
                            cs.CopyTo(dataStream);
                        }

                        if (reliable)
                        {
                            var counter        = (ushort)(Interlocked.Increment(ref _decryptCounter) - 1);
                            var messageCounter = data.Buffer.GetShort(data.Buffer.ReaderIndex);

                            if (counter != messageCounter)
                            {
                                throw new ProudException($"Invalid decrypt counter! Remote: {messageCounter} Local: {counter}");
                            }
                        }

                        var slice = data.Buffer.ReadSlice(data.Buffer.ReadableBytes - padding);
                        using (var dataStream = new ReadOnlyByteBufferStream(slice, false))
                        {
                            if (Hash.GetUInt32 <CRC32>(dataStream) != (uint)checksum)
                            {
                                throw new ProudException("Invalid checksum");
                            }

                            dataStream.Position = reliable ? 2 : 0;
                            dataStream.CopyTo(dst);
                        }
                    }
        }
Exemplo n.º 14
0
        /// <summary>
        /// 设置开发者接口信息(会自动开启开发者模式)。
        /// </summary>
        /// <param name="url">Url地址。</param>
        /// <param name="token">令牌。</param>
        /// <param name="aeskey">EncodingAESKey。</param>
        /// <param name="encryptMode">加密模式。</param>
        /// <returns>是否更新成功。</returns>
        public bool SetDevelopInterface(string url, string token, string aeskey, EncryptMode encryptMode)
        {
            //开启开发者模式。
            if (!SetDevelopMode(true))
            {
                throw new WeiXinWebApiException("更新开发者接口信息失败,因为开启开发者模式失败。");
            }

            using (var client = new LastingWebClient(_cookieContainer))
            {
                client.Headers.Add("Referer", "https://mp.weixin.qq.com/");
                client.Headers.Add("ContentType", "application/x-www-form-urlencoded");
                var data = client.UploadData(
                    string.Format("https://mp.weixin.qq.com/advanced/callbackprofile?t=ajax-response&token={0}&lang=zh_CN", LoginResult.Token),
                    "POST", Encoding.UTF8.GetBytes(string.Format("url={0}&callback_token={1}&encoding_aeskey={2}&callback_encrypt_mode={3}", HttpUtility.UrlEncode(url), token, aeskey, (int)encryptMode)));
                var json = Encoding.UTF8.GetString(data);
                return(json.Contains("\"err_msg\":\"ok\""));
            }
        }
Exemplo n.º 15
0
        /**
         *
         * @param _inputText
         *            Text to be encrypted or decrypted
         * @param _encryptionKey
         *            Encryption key to used for encryption / decryption
         * @param _mode
         *            specify the mode encryption / decryption
         * @param _initVector
         *            initialization vector
         * @return encrypted or decrypted string based on the mode
         */
        private String encryptDecrypt(string _inputText, string _encryptionKey, EncryptMode _mode, string _initVector)
        {
            string _out = "";// output string

            _pwd     = Encoding.UTF8.GetBytes(_encryptionKey);
            _ivBytes = Encoding.UTF8.GetBytes(_initVector);


            int len = _pwd.Length;

            if (len > _key.Length)
            {
                len = _key.Length;
            }
            int ivLenth = _ivBytes.Length;

            if (ivLenth > _iv.Length)
            {
                ivLenth = _iv.Length;
            }


            Array.Copy(_pwd, _key, len);
            Array.Copy(_ivBytes, _iv, ivLenth);
            _rcipher.Key = _key;
            _rcipher.IV  = _iv;


            if (_mode.Equals(EncryptMode.ENCRYPT))
            {
                //encrypt
                byte[] plainText = _rcipher.CreateEncryptor().TransformFinalBlock(_enc.GetBytes(_inputText), 0, _inputText.Length);
                _out = Convert.ToBase64String(plainText);
            }
            if (_mode.Equals(EncryptMode.DECRYPT))
            {
                //decrypt
                byte[] plainText = _rcipher.CreateDecryptor().TransformFinalBlock(Convert.FromBase64String(_inputText), 0, Convert.FromBase64String(_inputText).Length);
                _out = _enc.GetString(plainText);
            }
            _rcipher.Dispose();
            return(_out);// return encrypted/decrypted string
        }
Exemplo n.º 16
0
        /// <summary>
        /// 加密字符串(失败返回空)
        /// </summary>
        /// <param name="EncryptString">待加密字符串</param>
        /// <param name="Mode">加密模式</param>
        /// <returns></returns>
        public static string Encode(string EncryptString, EncryptMode Mode)
        {
            string             ReturnString = "";
            List <EncryptInfo> EncryptList  = EncryptConfigs.GetConfig().EncryptInfo;

            try {
                foreach (EncryptInfo el in EncryptList)
                {
                    EncryptMode TempMode = Utils.GetEnum <EncryptMode>(el.EncryptName.Trim(), EncryptMode.Default);

                    if (Mode.Equals(TempMode))
                    {
                        ReturnString = EncryptString;

                        //正向加密
                        foreach (EncryptType ei in el.EncryptType)
                        {
                            switch (ei.Type)
                            {
                            case EncryptEnum.AES:
                                ReturnString = AES.Encode(ReturnString, ei.Key);
                                break;

                            case EncryptEnum.DES:
                                ReturnString = DES.Encode(ReturnString, ei.Key);
                                break;

                            case EncryptEnum.MD5:
                                ReturnString = MD5.Encode(ReturnString);
                                break;

                            default:
                                break;
                            }
                        }
                        break;
                    }
                }
            }
            catch { ReturnString = ""; }

            return(ReturnString);
        }
Exemplo n.º 17
0
        public void Encrypt(IByteBufferAllocator allocator, EncryptMode mode, Stream src, Stream dst, bool reliable)
        {
            if (RC4 == null || AES == null)
            {
                return;
            }
            //throw new ObjectDisposedException(GetType().FullName);

            using (var data = new BufferWrapper(allocator.Buffer()))
                using (var encryptor = GetAlgorithm(mode).CreateEncryptor())
                    using (var cs = new CryptoStream(new NonClosingStream(dst), encryptor, CryptoStreamMode.Write))
                        using (var w = cs.ToBinaryWriter(false))
                        {
                            var blockSize = AES.BlockSize / 8;
                            var padding   = blockSize - ((src.Length + 1 + 4) % blockSize);
                            if (reliable)
                            {
                                padding = blockSize - ((src.Length + 1 + 4 + 2) % blockSize);
                            }

                            if (reliable)
                            {
                                var counter = (ushort)(Interlocked.Increment(ref _encryptCounter) - 1);
                                data.Buffer.WriteShortLE(counter);
                            }

                            using (var dataStream = new WriteOnlyByteBufferStream(data.Buffer, false))
                            {
                                src.CopyTo(dataStream);
                            }

                            w.Write((byte)padding);
                            using (var dataStream = new ReadOnlyByteBufferStream(data.Buffer, false))
                            {
                                w.Write(Hash.GetUInt32 <CRC32>(dataStream));
                                dataStream.Position = 0;
                                dataStream.CopyTo(cs);
                            }

                            w.Fill((int)padding);
                        }
        }
Exemplo n.º 18
0
        /**
         *
         * @param inputText
         *            Text to be encrypted or decrypted
         * @param encryptionKey
         *            Encryption key to used for encryption / decryption
         * @param mode
         *            specify the mode encryption / decryption
         * @param initVector
         *            initialization vector
         * @return encrypted or decrypted string based on the mode
         */

        private string EncryptDecrypt(string inputText, string encryptionKey, EncryptMode mode, string initVector)
        {
            string outputString = "";   // output string

            pwd     = Encoding.UTF8.GetBytes(encryptionKey);
            ivBytes = Encoding.UTF8.GetBytes(initVector);

            int len = pwd.Length;

            if (len > key.Length)
            {
                len = key.Length;
            }
            int ivLenth = ivBytes.Length;

            if (ivLenth > iv.Length)
            {
                ivLenth = iv.Length;
            }

            Array.Copy(pwd, key, len);
            Array.Copy(ivBytes, iv, ivLenth);
            rcipher.Key = key;
            rcipher.IV  = iv;

            if (mode.Equals(EncryptMode.ENCRYPT))
            {
                //encrypt
                byte[] plainText = rcipher.CreateEncryptor().TransformFinalBlock(enc.GetBytes(inputText), 0, inputText.Length);
                outputString = Convert.ToBase64String(plainText);
            }
            if (mode.Equals(EncryptMode.DECRYPT))
            {
                //decrypt
                byte[] plainText = rcipher.CreateDecryptor().TransformFinalBlock(Convert.FromBase64String(inputText), 0, Convert.FromBase64String(inputText).Length);
                outputString = enc.GetString(plainText);
            }
            rcipher.Dispose();
            return(outputString);// return encrypted/decrypted string
        }
Exemplo n.º 19
0
        private static string Encrypt(string text, EncryptMode mode)
        {
            switch (mode)
            {
            case EncryptMode.MD5:
                return(CryptographyUtils.MD5Encrypt(text));

            case EncryptMode.SHA1:
                return(CryptographyUtils.SHA1Encrypt(text));

            case EncryptMode.SHA256:
                return(CryptographyUtils.SHA256Encrypt(text));

            case EncryptMode.SHA384:
                return(CryptographyUtils.SHA384Encrypt(text));

            case EncryptMode.SHA512:
                return(CryptographyUtils.SHA512Encrypt(text));

            default:
                return(text);
            }
        }
        private static string encryptDecrypt(string _inputText, string _encryptionKey, EncryptMode _mode, string _initVector)
        {
            string _out = "";            // output string

            //_encryptionKey = MD5Hash (_encryptionKey);

            using (RijndaelManaged _rcipher = GetProvider(_encryptionKey, _initVector))
            {
                UTF8Encoding _enc = new UTF8Encoding();
                try
                {
                    if (_mode.Equals(EncryptMode.ENCRYPT))
                    {
                        //encrypt
                        byte[] plainText = _rcipher.CreateEncryptor().TransformFinalBlock(_enc.GetBytes(_inputText), 0, _inputText.Length);
                        _out = Convert.ToBase64String(plainText);
                    }
                    if (_mode.Equals(EncryptMode.DECRYPT))
                    {
                        //decrypt
                        byte[] plainText = _rcipher.CreateDecryptor().TransformFinalBlock(Convert.FromBase64String(_inputText), 0, Convert.FromBase64String(_inputText).Length);
                        _out = _enc.GetString(plainText);
                    }
                }
                catch (Exception ex) { throw; }
                finally { _rcipher.Dispose(); }
            }

            return(_out);           // return encrypted/decrypted string
        }
Exemplo n.º 21
0
 public static extern bool AddToWlanPreferredList([MarshalAs(UnmanagedType.LPWStr)]string szSSID, AuthMode authMode, EncryptMode encryptMode, [MarshalAs(UnmanagedType.LPWStr)]string szKey, EapType eapType, [MarshalAs(UnmanagedType.Bool)]bool bAdhoc);
Exemplo n.º 22
0
        public D3DesKey(byte[] key, EncryptMode mode)
        {
            int l;
            int m;

            byte[]   pc1m = new byte[56];
            byte[]   pcr  = new byte[56];
            UInt32[] kn   = new UInt32[32];

            for (int j = 0; j < 56; j++)
            {
                l       = pc1[j];
                m       = l & 7;
                pc1m[j] = (byte)((key[l >> 3] & bytebit[m]) != 0? 1 : 0);
            }
            for (int i = 0; i < 16; i++)
            {
                int n;

                if (mode == EncryptMode.DE1)
                {
                    m = (15 - i) << 1;
                }
                else if (mode == EncryptMode.EN0)
                {
                    m = i << 1;
                }
                else
                {
                    throw new ArgumentException("mode", "Not a valid encryption mode");
                }
                n     = m + 1;
                kn[m] = 0;
                kn[n] = 0;
                for (int j = 0; j < 28; j++)
                {
                    l = j + totrot[i];
                    if (l < 28)
                    {
                        pcr[j] = pc1m[l];
                    }
                    else
                    {
                        pcr[j] = pc1m[l - 28];
                    }
                }
                for (int j = 28; j < 56; j++)
                {
                    l = j + totrot[i];
                    if (l < 56)
                    {
                        pcr[j] = pc1m[l];
                    }
                    else
                    {
                        pcr[j] = pc1m[l - 28];
                    }
                }
                for (int j = 0; j < 24; j++)
                {
                    if (pcr[pc2[j]] != 0)
                    {
                        kn[m] |= bigbyte[j];
                    }
                    if (pcr[pc2[j + 24]] != 0)
                    {
                        kn[n] |= bigbyte[j];
                    }
                }
            }
            cookey(kn);
        }
Exemplo n.º 23
0
        private void SettingGUI()
        {
            if (_showSetting)
            {
                int width = 325, height = 290;

                GUI.BeginGroup(new Rect((int)position.width / 2 - width / 2, (int)position.height / 2 - height / 2, width, height), "", _flownode0on);
                //-----------Build Target
                GUI.Label(new Rect(5, 5, 100, 20), "Build Target:", "HeaderLabel");
                GUI.BeginGroup(new Rect(5, 25, 315, 135), _box);
                // string[] buildTargets = Enum.GetNames(typeof(BuildTarget));
                _buildTargetScrollView = GUI.BeginScrollView(new Rect(0, 2, 313, 132), _buildTargetScrollView,
                                                             new Rect(0, 0, 180, 20 * _buildTargets.Count), false, true);
                int index = 0;
                foreach (var item in _buildTargets)
                {
                    bool value = GUI.Toggle(new Rect(5, 20 * index, 180, 20), item.Value, item.Key);
                    if (value != item.Value)
                    {
                        _buildTargets[item.Key] = value;
                        break;
                    }
                    index++;
                }
                GUI.EndScrollView();
                GUI.EndGroup();
                //--------Zip Mode
                GUI.Label(new Rect(5, 165, 60, 20), "Zip Mode:", "HeaderLabel");
                ZipMode zipMode = (ZipMode)EditorGUI.EnumPopup(new Rect(75, 165, 240, 20), _zipMode, _preDropDown);
                if (zipMode != _zipMode)
                {
                    _zipMode = zipMode;
                    AssetBundleTool.EditorConfigInfo.ZipMode = (int)_zipMode;
                    AssetBundleTool.SaveEditorConfigInfo();
                }
                //----------Encrypt
                GUI.Label(new Rect(5, 190, 60, 20), "Encrypt: ", "HeaderLabel");
                EncryptMode encryptMode = (EncryptMode)EditorGUI.EnumPopup(new Rect(75, 190, 240, 20), _encryptMode, _preDropDown);
                if (encryptMode != _encryptMode)
                {
                    _encryptMode = encryptMode;
                    AssetBundleTool.EditorConfigInfo.EncryptMode = (int)encryptMode;
                    AssetBundleTool.SaveEditorConfigInfo();
                }
                // ----------Assets Version
                GUI.Label(new Rect(5, 215, 150, 20), "Asset Version: " + _assetVersion, "HeaderLabel");
                if (GUI.Button(new Rect(160, 215, 95, 20), "Reset", _preButton))
                {
                    _assetVersion = 1;
                    AssetBundleTool.EditorConfigInfo.AssetVersion = _assetVersion;
                    AssetBundleTool.SaveEditorConfigInfo();
                }
                //sure cancel
                if (GUI.Button(new Rect(92.5f, 255, 140, 20), "Sure", _preButton))
                {
                    //更新目标平台
                    foreach (var item in _buildTargets)
                    {
                        BuildTarget target  = (BuildTarget)Enum.Parse(typeof(BuildTarget), (item.Key));
                        int         iTarget = (int)target;
                        if (item.Value)
                        {
                            if (!AssetBundleTool.EditorConfigInfo.BuildTargets.Contains(iTarget))
                            {
                                AssetBundleTool.EditorConfigInfo.BuildTargets.Add(iTarget);
                            }
                        }
                        else
                        {
                            if (AssetBundleTool.EditorConfigInfo.BuildTargets.Contains(iTarget))
                            {
                                AssetBundleTool.EditorConfigInfo.BuildTargets.Remove(iTarget);
                            }
                        }
                    }
                    //保存配置文件
                    AssetBundleTool.SaveEditorConfigInfo();

                    _showSetting = false;
                }
                //if (GUI.Button(new Rect(175, 255, 140, 20), "Cancel", _preButton))
                //{
                //    _showSetting = false;
                //}
                GUI.EndGroup();
            }
        }
        /***
         * This function decrypts the encrypted text to plain text using the key
         * provided. You'll have to use the same key which you used during
         * encryption
         *
         * @param _encryptedText
         *            Encrypted/Cipher text to be decrypted
         * @param _key
         *            Encryption key which you used during encryption
         */
        private string encryptDecrypt(string _inputText, string _encryptionKey, EncryptMode _mode, string _initVector)
        {
            SymmetricKeyAlgorithmProvider aesCbcPkcs7 = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);

            // Creata a 16 byte initialization vector
            IBuffer iv = CryptographicBuffer.ConvertStringToBinary(_initVector, BinaryStringEncoding.Utf8);

            // Create an AES 128-bit (16 byte) key
            IBuffer keyMaterial = CryptographicBuffer.ConvertStringToBinary(_encryptionKey, BinaryStringEncoding.Utf8);
            CryptographicKey key = aesCbcPkcs7.CreateSymmetricKey(keyMaterial);

            if (_mode.Equals(EncryptMode.ENCRYPT))
            {
                // Encrypt the data
                IBuffer plainText = CryptographicBuffer.ConvertStringToBinary(_inputText, BinaryStringEncoding.Utf8);
                IBuffer cipherText = CryptographicEngine.Encrypt(key, plainText, iv);
                string strEncrypted64 = CryptographicBuffer.EncodeToBase64String(cipherText);
                return strEncrypted64;
            }
            else
            {
                // Decrypt the data
                IBuffer cipherText = CryptographicBuffer.DecodeFromBase64String(_inputText);
                IBuffer decryptedText = CryptographicEngine.Decrypt(key, cipherText, iv);
                return CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, decryptedText);
            }
        }
Exemplo n.º 25
0
 public static string Encrypt(string encryptString, EncryptMode encryptMode, Encoding encoding)
 {
     string returnString = "";
     System.Security.Cryptography.HashAlgorithm hash;
     byte[] sString = encoding.GetBytes(encryptString);
     switch (encryptMode.ToString())
     {
         case "md5":
             hash = new MD5CryptoServiceProvider();
             byte[] md5data = hash.ComputeHash(sString);
             hash.Clear();
             StringBuilder sb = new StringBuilder();
             for (int i = 0; i < md5data.Length; i++)
             {
                 sb.Append(md5data[i].ToString("x").PadLeft(2, '0'));
             }
             returnString = sb.ToString();
             break;
         case "sha1":
             hash = new SHA1CryptoServiceProvider();
             returnString = Convert.ToBase64String(hash.ComputeHash(sString));
             break;
         case "sha256":
             hash = new SHA256Managed();
             returnString = Convert.ToBase64String(hash.ComputeHash(sString));
             break;
         case "sha384":
             hash = new SHA384Managed();
             returnString = Convert.ToBase64String(hash.ComputeHash(sString));
             break;
         case "sha512":
             hash = new SHA512Managed();
             returnString = Convert.ToBase64String(hash.ComputeHash(sString));
             break;
         default:
             returnString = String.Empty;
             break;
     }
     return returnString;
 }
Exemplo n.º 26
0
        /**
         *
         * @param _inputText
         *            Text to be encrypted or decrypted
         * @param _encryptionKey
         *            Encryption key to used for encryption / decryption
         * @param _mode
         *            specify the mode encryption / decryption
         * @param _initVector
         * 			  initialization vector
         * @return encrypted or decrypted string based on the mode
        */
        private byte[] doEncryptDecrypt(byte[] _inputText, string _encryptionKey, EncryptMode _mode, string _initVector)
        {
            byte[] _out = _inputText;// output string
            //_encryptionKey = MD5Hash (_encryptionKey);
            _pwd = System.Text.Encoding.UTF8.GetBytes(_encryptionKey);
            _ivBytes = System.Text.Encoding.UTF8.GetBytes(_initVector);

            int len = _pwd.Length;
            if (len > _key.Length)
            {
                len = _key.Length;
            }
            int ivLenth = _ivBytes.Length;
            if (ivLenth > _iv.Length)
            {
                ivLenth = _iv.Length;
            }

            Array.Copy(_pwd, _key, len);
            Array.Copy(_ivBytes, _iv, ivLenth);
            _rcipher.Key = _key;
            _rcipher.IV = _iv;

            if (_mode.Equals(EncryptMode.ENCRYPT))
            {
                //encrypt
                //byte[] plainText = _rcipher.CreateEncryptor().TransformFinalBlock(_enc.GetBytes(_inputText), 0, _inputText.Length);
                _out = _rcipher.CreateEncryptor().TransformFinalBlock(_inputText, 0, _inputText.Length);
                //_out = Convert.ToBase64String(plainText);
            }
            if (_mode.Equals(EncryptMode.DECRYPT))
            {
                //decrypt
                //byte[] plainText = _rcipher.CreateDecryptor().TransformFinalBlock(Convert.FromBase64String(_inputText), 0, Convert.FromBase64String(_inputText).Length);
                _out = _rcipher.CreateDecryptor().TransformFinalBlock(_inputText, 0, _inputText.Length);
                //_out = _enc.GetString(plainText);
            }
            _rcipher.Dispose();
            return _out;// return encrypted/decrypted string
        }
Exemplo n.º 27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="passwordSalt"></param>
 /// <param name="encryptMode"></param>
 public EncryptMetaInfo(string passwordSalt, EncryptMode encryptMode)
 {
     PasswordSalt = passwordSalt;
     EncryptMode  = encryptMode;
 }
Exemplo n.º 28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="passwordSalt"></param>
 public EncryptMetaInfo(string passwordSalt)
 {
     PasswordSalt = passwordSalt;
     EncryptMode  = EncryptMode.SHA1;
 }
Exemplo n.º 29
0
 public static extern bool AddToWlanPreferredList([MarshalAs(UnmanagedType.LPWStr)] string szSSID, AuthMode authMode, EncryptMode encryptMode, [MarshalAs(UnmanagedType.LPWStr)] string szKey, EapType eapType, [MarshalAs(UnmanagedType.Bool)] bool bAdhoc);
Exemplo n.º 30
0
 public EncryptedReliableMessage(byte[] data, EncryptMode encryptMode)
 {
     Data        = data;
     EncryptMode = encryptMode;
 }
Exemplo n.º 31
0
        /// <summary>
        /// 设置开发者接口信息(会自动开启开发者模式)。
        /// </summary>
        /// <param name="url">Url地址。</param>
        /// <param name="token">令牌。</param>
        /// <param name="aeskey">EncodingAESKey。</param>
        /// <param name="encryptMode">加密模式。</param>
        /// <returns>是否更新成功。</returns>
        public bool SetDevelopInterface(string url, string token, string aeskey, EncryptMode encryptMode)
        {
            //开启开发者模式。
            if (!SetDevelopMode(true))
                throw new WeiXinWebApiException("更新开发者接口信息失败,因为开启开发者模式失败。");

            using (var client = new LastingWebClient(_cookieContainer))
            {
                client.Headers.Add("Referer", "https://mp.weixin.qq.com/");
                client.Headers.Add("ContentType", "application/x-www-form-urlencoded");
                var data = client.UploadData(
                    string.Format("https://mp.weixin.qq.com/advanced/callbackprofile?t=ajax-response&token={0}&lang=zh_CN", LoginResult.Token),
                    "POST", Encoding.UTF8.GetBytes(string.Format("url={0}&callback_token={1}&encoding_aeskey={2}&callback_encrypt_mode={3}", HttpUtility.UrlEncode(url), token, aeskey, (int)encryptMode)));
                var json = Encoding.UTF8.GetString(data);
                return json.Contains("\"err_msg\":\"ok\"");
            }
        }
Exemplo n.º 32
0
        /**
         *
         * @param _inputText
         *            Text to be encrypted or decrypted
         * @param _encryptionKey
         *            Encryption key to used for encryption / decryption
         * @param _mode
         *            specify the mode encryption / decryption
         * @param _initVector
         *            initialization vector
         * @return encrypted or decrypted string based on the mode
         */
        private String encryptDecrypt(byte[] _encryptDecryptBytes, string _encryptionKey, EncryptMode _mode, string _initVector)
        {
            // initialization
            _aes           = Aes.Create();
            _aes.Mode      = CipherMode.CBC;
            _aes.Padding   = PaddingMode.PKCS7;
            _aes.KeySize   = 256;
            _aes.BlockSize = 128;

            byte[] _key     = new byte[32];
            byte[] _iv      = new byte[_aes.BlockSize / 8]; //128 bit / 8 = 16 bytes
            byte[] _pwd     = Encoding.UTF8.GetBytes(_encryptionKey);
            byte[] _ivBytes = Encoding.UTF8.GetBytes(_initVector);

            try
            {
                string _out = string.Empty; // output string
                                            //_encryptionKey = MD5Hash (_encryptionKey);

                int len = _pwd.Length;
                if (len > _key.Length)
                {
                    len = _key.Length;
                }
                int ivLenth = _ivBytes.Length;
                if (ivLenth > _iv.Length)
                {
                    ivLenth = _iv.Length;
                }

                Array.Copy(_pwd, _key, len);
                Array.Copy(_ivBytes, _iv, ivLenth);
                _aes.Key = _key;
                _aes.IV  = _iv;

                if (_mode.Equals(EncryptMode.ENCRYPT))
                {
                    //encrypt
                    using (var memoryStream = new MemoryStream())
                    {
                        using (var encryptor = _aes.CreateEncryptor())
                        {
                            using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                            {
                                cryptoStream.Write(_encryptDecryptBytes, 0, _encryptDecryptBytes.Length);
                                cryptoStream.Close();
                                _out = Convert.ToBase64String(memoryStream.ToArray());
                            }
                        }
                    }
                }
                if (_mode.Equals(EncryptMode.DECRYPT))
                {
                    //decrypt
                    using (var memoryStream = new MemoryStream())
                    {
                        using (var decryptor = _aes.CreateDecryptor())
                        {
                            using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Write))
                            {
                                cryptoStream.Write(_encryptDecryptBytes, 0, _encryptDecryptBytes.Length);
                                cryptoStream.Close();
                                _out = Encoding.UTF8.GetString(memoryStream.ToArray());
                            }
                        }
                    }
                }
                return(_out);// return encrypted/decrypted string
            }
            finally
            {
                Array.Clear(_key, 0, _key.Length);
                Array.Clear(_pwd, 0, _pwd.Length);
                Array.Clear(_ivBytes, 0, _ivBytes.Length);
                Array.Clear(_iv, 0, _iv.Length);

                _aes.Dispose();
            }
        }
Exemplo n.º 33
0
 private void menuItem_ToggleEncryptMode_Click(object sender, RoutedEventArgs e)
 {
     MenuItem modeMenu = (MenuItem)sender;
     if (this.encryptMode == EncryptMode.PerChar)    // 改成一次加密
     {
         this.encryptMode = EncryptMode.PerString;
         modeMenu.Header = "Encrypt Mode: After confirm";
         this.button_Encrypt.IsEnabled = true;
         this.textBox_Input.IsReadOnly = false;
     }
     else    // 改成每次加密
     {
         this.encryptMode = EncryptMode.PerChar;
         modeMenu.Header = "Encrypt Mode: Traditional";
         this.button_Encrypt.IsEnabled = false;
         this.textBox_Input.IsReadOnly = true;
         this.textBox_Input.Clear();
         this.textBox_Output.Clear();
     }
 }
Exemplo n.º 34
0
 public void SetEncryption(string password, EncryptMode mode) {
   byte[] pwdBytes = null;
   Util.StrToUtf8(password, ref pwdBytes);
   DbRetVal ret;
   lock (rscLock) {
     DB_ENV* evp = CheckDisposed();
     fixed (byte* pwd = pwdBytes) {
       ret = evp->SetEncrypt(evp, pwd, mode);
     }
   }
   Util.CheckRetVal(ret);
 }