Exemple #1
0
        protected byte [] EncryptMsg(string msgOut)
        {
            byte[] byMsgOut = new byte[System.Text.Encoding.Default.GetByteCount(msgOut.ToCharArray(), 0, msgOut.Length)];
            System.Text.Encoding.Default.GetBytes(msgOut, 0, msgOut.Length, byMsgOut, 0);
            byMsgOut = DropUnWantedChars(byMsgOut);
            TripleDESCryptoServiceProvider TripleDesProvider = new TripleDESCryptoServiceProvider();
            int sizeKey = System.Text.Encoding.UTF8.GetByteCount(KEY_MESSAGE_5);

            byte [] byKey;
            byKey = new byte[sizeKey];
            System.Text.Encoding.UTF8.GetBytes(KEY_MESSAGE_5, 0, KEY_MESSAGE_5.Length, byKey, 0);
            TripleDesProvider.Mode = CipherMode.ECB;
            TripleDesProvider.Key  = byKey;
            Array.Clear(TripleDesProvider.IV, 0, TripleDesProvider.IV.Length);

            OPSTripleDesEncryptor OPSTripleDesEnc = new OPSTripleDesEncryptor(TripleDesProvider);

            byte [] byRes = null;
            byte [] byTemp;

            byTemp = OPSTripleDesEnc.Encriptar(byMsgOut);

            byRes = null;
            byRes = new byte[byTemp.Length];
            Array.Copy(byTemp, 0, byRes, 0, byTemp.Length);
            return(byRes);
        }
        private static string encrypt(string strDecrypt)
        {
            string strKey = KEY_MESSAGE_TCP_5;

            byte [] byDecrypt;
            string  strRes = "";

            int sizeDecrypt = System.Text.Encoding.Default.GetByteCount(strDecrypt);

            byDecrypt = new byte[sizeDecrypt];
            System.Text.Encoding.Default.GetBytes(strDecrypt, 0, strDecrypt.Length, byDecrypt, 0);

            TripleDESCryptoServiceProvider TripleDesProvider = new TripleDESCryptoServiceProvider();
            int sizeKey = System.Text.Encoding.Default.GetByteCount(strKey);

            byte [] byKey;
            byKey = new byte[sizeKey];
            System.Text.Encoding.Default.GetBytes(strKey, 0, strKey.Length, byKey, 0);
            TripleDesProvider.Mode = CipherMode.ECB;
            TripleDesProvider.Key  = byKey;
            Array.Clear(TripleDesProvider.IV, 0, TripleDesProvider.IV.Length);

            OPSTripleDesEncryptor OPSTripleDesEnc = new OPSTripleDesEncryptor(TripleDesProvider);

            byte [] byEncrypt;

            byEncrypt = OPSTripleDesEnc.Encriptar(byDecrypt);

            strRes = Bytes_To_HexString(byEncrypt);

            return(strRes);
        }
Exemple #3
0
        protected string DecryptMsg(byte [] msgIn)
        {
            TripleDESCryptoServiceProvider TripleDesProvider = new TripleDESCryptoServiceProvider();
            int sizeKey = System.Text.Encoding.UTF8.GetByteCount(KEY_MESSAGE_5);

            byte [] byKey;
            byKey = new byte[sizeKey];
            System.Text.Encoding.UTF8.GetBytes(KEY_MESSAGE_5, 0, KEY_MESSAGE_5.Length, byKey, 0);
            TripleDesProvider.Mode = CipherMode.ECB;
            TripleDesProvider.Key  = byKey;
            Array.Clear(TripleDesProvider.IV, 0, TripleDesProvider.IV.Length);

            OPSTripleDesEncryptor OPSTripleDesEnc = new OPSTripleDesEncryptor(TripleDesProvider);

            byte [] byRes = null;
            byte [] byTemp;

            byTemp = OPSTripleDesEnc.Desencriptar(msgIn);

            byRes = null;
            byRes = new byte[byTemp.Length];
            Array.Copy(byTemp, 0, byRes, 0, byTemp.Length);
            return(GetDataAsString(byRes));
        }