예제 #1
0
        private EncryptDecryptKey GetEncryptKey()
        {
            EncryptDecryptKey okey   = new EncryptDecryptKey();
            string            encKey = "";
            Random            random = new Random();
            int i = random.Next(25);

            encKey        = _generateKey[i];
            okey.KeyIndex = i;
            okey.KeyValue = encKey;
            return(okey);
        }
예제 #2
0
 public string Encrypt(string stringToEncrypt)
 {
     try
     {
         _encryptDecryptKey = GetEncryptKey();
         _key = Encoding.UTF8.GetBytes(_encryptDecryptKey.KeyValue);
         DESCryptoServiceProvider des = new DESCryptoServiceProvider();
         byte[]       inputByteArray  = Encoding.UTF8.GetBytes(stringToEncrypt);
         MemoryStream ms = new MemoryStream();
         CryptoStream cs = new CryptoStream(ms,
                                            des.CreateEncryptor(_key, _iv), CryptoStreamMode.Write);
         cs.Write(inputByteArray, 0, inputByteArray.Length);
         cs.FlushFinalBlock();
         return(Convert.ToBase64String(ms.ToArray()) + _encryptDecryptKey.KeyIndex.ToString("00"));
     }
     catch (Exception e)
     {
         return(e.Message);
     }
 }