예제 #1
0
        public string EncryptString(string value, string keyString)
        {
            try
            {
                byte[] resultBA = new byte[value.Length], valueBA = new byte[value.Length];
                byte[] iv       = new byte[] { 0x14, 0xD7, 0x5B, 0xA2, 0x47, 0x83, 0x0F, 0xC4 };
                System.Text.ASCIIEncoding ascEncoding = new System.Text.ASCIIEncoding();
                byte[] key = new byte[24];
                ascEncoding.GetBytes(keyString, 0, keyString.Length < 24?keyString.Length:24, key, 0);

                MemoryStream memStream = new MemoryStream();
                byte[]       tempBA    = new byte[value.Length];
                ascEncoding.GetBytes(value, 0, value.Length, tempBA, 0);
                System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream(memStream, System.Security.Cryptography.TripleDESCryptoServiceProvider.Create().CreateEncryptor(key, iv), System.Security.Cryptography.CryptoStreamMode.Write);
                cStream.Write(tempBA, 0, tempBA.Length);
                cStream.FlushFinalBlock();
                resultBA = memStream.ToArray();
                cStream.Close();


                return(InternalMethods.BytesToHexString(resultBA));
            }
            catch (Exception exc)
            {
                LogEvent(exc.Source, "EncryptString()", exc.ToString(), 4);
                return("");
            }
        }
예제 #2
0
 public string ConvertBinaryToHex(byte[] binary)
 {
     try
     {
         return(InternalMethods.BytesToHexString(binary));
     }
     catch (Exception exc)
     {
         LogInternalEvent(exc, 4);
         throw exc;
     }
 }
예제 #3
0
 public byte[] ConvertHexToBinary(string hex_text)
 {
     try
     {
         return(InternalMethods.HexStringToBytes(hex_text));
     }
     catch (Exception exc)
     {
         LogInternalEvent(exc, 4);
         throw exc;
     }
 }
예제 #4
0
        public string DecryptString(string value, string keyString)
        {
            try
            {
                byte[] resultBA = new byte[value.Length / 2], valueBA = new byte[value.Length / 2];
                byte[] iv       = new byte[] { 0x14, 0xD7, 0x5B, 0xA2, 0x47, 0x83, 0x0F, 0xC4 };
                System.Text.ASCIIEncoding ascEncoding = new System.Text.ASCIIEncoding();
                byte[] key = new byte[24];
                ascEncoding.GetBytes(keyString, 0, keyString.Length < 24?keyString.Length:24, key, 0);

                MemoryStream memStream = new MemoryStream();
                byte[]       tempBA    = InternalMethods.HexStringToBytes(value);
                memStream.Write(tempBA, 0, tempBA.Length);
                memStream.Position = 0;

                System.Security.Cryptography.TripleDES
                    cryptoServiceProvider = System.Security.Cryptography.TripleDESCryptoServiceProvider.Create();

                System.Security.Cryptography.ICryptoTransform
                    decryptor = cryptoServiceProvider.CreateDecryptor(key, iv);

                System.Security.Cryptography.CryptoStream
                    cStream = new System.Security.Cryptography.CryptoStream(
                    memStream,
                    decryptor,
                    System.Security.Cryptography.CryptoStreamMode.Read);

                cStream.Read(resultBA, 0, resultBA.Length);
                cStream.Close();

                return(ascEncoding.GetString(resultBA));
            }
            catch (Exception exc)
            {
                LogEvent("Decryption failure.  Returning original value" +
                         Environment.NewLine + exc.Source, "DecryptString()", exc.ToString(), 3);
                return(value);
            }
        }