Ejemplo n.º 1
0
 public static string CutStringProlongSymbol(string originalVal, int cutLength)
 {
     if (originalVal.Length <= cutLength)
     {
         return(originalVal);
     }
     return(TextUtility.CutLeft(originalVal, cutLength) + TextUtility.PROLONG_SYMBOL);
 }
Ejemplo n.º 2
0
 public static string CutStringProlongSymbol(string originalVal, int cutLength, string prolongSymbol)
 {
     if (string.IsNullOrEmpty(prolongSymbol))
     {
         prolongSymbol = TextUtility.PROLONG_SYMBOL;
     }
     return(TextUtility.CutLeft(originalVal, cutLength) + prolongSymbol);
 }
Ejemplo n.º 3
0
        public static string Encrypt(string plainText, string cipherkey)
        {
            cipherkey = TextUtility.CutLeft(cipherkey, 0x20);
            cipherkey = cipherkey.PadRight(0x20, ' ');
            ICryptoTransform transform = new RijndaelManaged {
                Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 0x20)), IV = Keys
            }.CreateEncryptor();

            byte[] bytes = Encoding.UTF8.GetBytes(plainText);
            return(Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length)));
        }
Ejemplo n.º 4
0
        public static byte[] EncryptBuffer(byte[] plainText, string cipherkey)
        {
            cipherkey = TextUtility.CutLeft(cipherkey, 0x20);
            cipherkey = cipherkey.PadRight(0x20, ' ');
            RijndaelManaged managed = new RijndaelManaged {
                Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 0x20)),
                IV  = Keys
            };

            return(managed.CreateEncryptor().TransformFinalBlock(plainText, 0, plainText.Length));
        }
Ejemplo n.º 5
0
        public static byte[] EncryptBuffer(byte[] plainText, string cipherkey)
        {
            cipherkey = TextUtility.CutLeft(cipherkey, 32);
            cipherkey = cipherkey.PadRight(32, ' ');
            RijndaelManaged rijndaelManaged = new RijndaelManaged();

            rijndaelManaged.Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 32));
            rijndaelManaged.IV  = Keys;
            RijndaelManaged rijndaelManaged2 = rijndaelManaged;

            return(rijndaelManaged2.CreateEncryptor().TransformFinalBlock(plainText, 0, plainText.Length));
        }
Ejemplo n.º 6
0
        public static string Encrypt(string plainText, string cipherkey)
        {
            cipherkey = TextUtility.CutLeft(cipherkey, 32);
            cipherkey = cipherkey.PadRight(32, ' ');
            RijndaelManaged rijndaelManaged = new RijndaelManaged();

            rijndaelManaged.Key = Encoding.UTF8.GetBytes(cipherkey.Substring(0, 32));
            rijndaelManaged.IV  = Keys;
            ICryptoTransform cryptoTransform = rijndaelManaged.CreateEncryptor();

            byte[] bytes = Encoding.UTF8.GetBytes(plainText);
            return(Convert.ToBase64String(cryptoTransform.TransformFinalBlock(bytes, 0, bytes.Length)));
        }
Ejemplo n.º 7
0
        public static string Encrypt(string encryptString, string encryptKey)
        {
            encryptKey = TextUtility.CutLeft(encryptKey, 8);
            encryptKey = encryptKey.PadRight(8, ' ');
            byte[] bytes  = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
            byte[] keys   = Keys;
            byte[] buffer = Encoding.UTF8.GetBytes(encryptString);
            DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
            MemoryStream             stream   = new MemoryStream();
            CryptoStream             stream2  = new CryptoStream(stream, provider.CreateEncryptor(bytes, keys), CryptoStreamMode.Write);

            stream2.Write(buffer, 0, buffer.Length);
            stream2.FlushFinalBlock();
            return(Convert.ToBase64String(stream.ToArray()));
        }
Ejemplo n.º 8
0
 public static byte[] DecryptBuffer(byte[] cipherText, string cipherkey)
 {
     try
     {
         cipherkey = TextUtility.CutLeft(cipherkey, 0x20);
         cipherkey = cipherkey.PadRight(0x20, ' ');
         RijndaelManaged managed = new RijndaelManaged {
             Key = Encoding.UTF8.GetBytes(cipherkey),
             IV  = Keys
         };
         return(managed.CreateDecryptor().TransformFinalBlock(cipherText, 0, cipherText.Length));
     }
     catch
     {
         return(null);
     }
 }
Ejemplo n.º 9
0
 public static byte[] DecryptBuffer(byte[] cipherText, string cipherkey)
 {
     try
     {
         cipherkey = TextUtility.CutLeft(cipherkey, 32);
         cipherkey = cipherkey.PadRight(32, ' ');
         RijndaelManaged rijndaelManaged = new RijndaelManaged();
         rijndaelManaged.Key = Encoding.UTF8.GetBytes(cipherkey);
         rijndaelManaged.IV  = Keys;
         RijndaelManaged rijndaelManaged2 = rijndaelManaged;
         return(rijndaelManaged2.CreateDecryptor().TransformFinalBlock(cipherText, 0, cipherText.Length));
     }
     catch
     {
         return(null);
     }
 }
Ejemplo n.º 10
0
 public static string Decrypt(string cipherText, string cipherkey)
 {
     try
     {
         cipherkey = TextUtility.CutLeft(cipherkey, 0x20);
         cipherkey = cipherkey.PadRight(0x20, ' ');
         ICryptoTransform transform = new RijndaelManaged {
             Key = Encoding.UTF8.GetBytes(cipherkey), IV = Keys
         }.CreateDecryptor();
         byte[] inputBuffer = Convert.FromBase64String(cipherText);
         byte[] bytes = transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length);
         return(Encoding.UTF8.GetString(bytes));
     }
     catch
     {
         return("");
     }
 }
Ejemplo n.º 11
0
 public static string Decrypt(string cipherText, string cipherkey)
 {
     try
     {
         cipherkey = TextUtility.CutLeft(cipherkey, 32);
         cipherkey = cipherkey.PadRight(32, ' ');
         RijndaelManaged rijndaelManaged = new RijndaelManaged();
         rijndaelManaged.Key = Encoding.UTF8.GetBytes(cipherkey);
         rijndaelManaged.IV  = Keys;
         ICryptoTransform cryptoTransform = rijndaelManaged.CreateDecryptor();
         byte[]           array           = Convert.FromBase64String(cipherText);
         byte[]           bytes           = cryptoTransform.TransformFinalBlock(array, 0, array.Length);
         return(Encoding.UTF8.GetString(bytes));
     }
     catch
     {
         return("");
     }
 }
Ejemplo n.º 12
0
 public static byte[] DecryptBuffer(byte[] cipherText, string cipherkey)
 {
     byte[] result;
     try
     {
         cipherkey = TextUtility.CutLeft(cipherkey, 32);
         cipherkey = cipherkey.PadRight(32, ' ');
         RijndaelManaged rijndaelManaged = new RijndaelManaged
         {
             Key = Encoding.UTF8.GetBytes(cipherkey),
             IV  = AES.Keys
         };
         result = rijndaelManaged.CreateDecryptor().TransformFinalBlock(cipherText, 0, cipherText.Length);
     }
     catch
     {
         result = null;
     }
     return(result);
 }
Ejemplo n.º 13
0
 public static string Decrypt(string decryptString, string decryptKey)
 {
     try
     {
         decryptKey = TextUtility.CutLeft(decryptKey, 8);
         decryptKey = decryptKey.PadRight(8, ' ');
         byte[] bytes  = Encoding.UTF8.GetBytes(decryptKey);
         byte[] keys   = Keys;
         byte[] buffer = Convert.FromBase64String(decryptString);
         DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
         MemoryStream             stream   = new MemoryStream();
         CryptoStream             stream2  = new CryptoStream(stream, provider.CreateDecryptor(bytes, keys), CryptoStreamMode.Write);
         stream2.Write(buffer, 0, buffer.Length);
         stream2.FlushFinalBlock();
         return(Encoding.UTF8.GetString(stream.ToArray()));
     }
     catch
     {
         return("");
     }
 }
Ejemplo n.º 14
0
        public static string Decrypt(string cipherText, string cipherkey)
        {
            string result;

            try
            {
                cipherkey = TextUtility.CutLeft(cipherkey, 32);
                cipherkey = cipherkey.PadRight(32, ' ');
                ICryptoTransform cryptoTransform = new RijndaelManaged
                {
                    Key = Encoding.UTF8.GetBytes(cipherkey),
                    IV  = AES.Keys
                }.CreateDecryptor();
                byte[] array = Convert.FromBase64String(cipherText);
                byte[] bytes = cryptoTransform.TransformFinalBlock(array, 0, array.Length);
                result = Encoding.UTF8.GetString(bytes);
            }
            catch
            {
                result = "";
            }
            return(result);
        }
Ejemplo n.º 15
0
        public static string Decrypt(string decryptString, string decryptKey)
        {
            string result;

            try
            {
                decryptKey = TextUtility.CutLeft(decryptKey, 8);
                decryptKey = decryptKey.PadRight(8, ' ');
                byte[] bytes = Encoding.UTF8.GetBytes(decryptKey);
                byte[] keys  = DES.Keys;
                byte[] array = Convert.FromBase64String(decryptString);
                DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
                MemoryStream             memoryStream             = new MemoryStream();
                CryptoStream             cryptoStream             = new CryptoStream(memoryStream, dESCryptoServiceProvider.CreateDecryptor(bytes, keys), CryptoStreamMode.Write);
                cryptoStream.Write(array, 0, array.Length);
                cryptoStream.FlushFinalBlock();
                result = Encoding.UTF8.GetString(memoryStream.ToArray());
            }
            catch
            {
                result = "";
            }
            return(result);
        }